Java swing drop down menu implementation method

  • 2020-04-01 04:11:47
  • OfStack

This article illustrates the swing drop-down menu implementation in Java. Share with you for your reference. The details are as follows:


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class test extends JApplet
implements ItemListener{
  JLabel jtf;
  ImageIcon a1, a2, a3;
  public void init(){
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    JComboBox jc = new JComboBox();
    jc.addItem("6");
    jc.addItem("7");
    jc.addItem("8");
    jc.addItemListener(this);
    contentPane.add(jc);
    jtf = new JLabel(new ImageIcon("D:/data/Images/6.gif"));
    contentPane.add(jtf);
  }
  public void itemStateChanged(ItemEvent ie){
    String s = (String)ie.getItem();
    jtf.setIcon(new ImageIcon("D:/data/Images/"+s+".gif"));
  }
}

I hope this article has been helpful to your Java programming.


Related articles: