Login    New User    Forgot Password    Help      

ComboBox

Java Tutorials

Example

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

 

public class swing4 extends JApplet
implements ItemListener
{
JLabel jl;

ImageIcon France, Germany, Italy, Japan;

public void init()
{

Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());

JComboBox jc = new JComboBox();

jc.addItem("France");
jc.addItem("Germany");
jc.addItem("Italy");
jc.addItem("Japan");
jc.addItemListener(this);
contentPane.add(jc);

jl = new JLabel(new ImageIcon("image1.jpg"));
contentPane.add(jl);
}

public void itemStateChanged(ItemEvent ie)
{
String s = (String)ie.getItem();
jl.setIcon(new ImageIcon(s + ".jpg"));
}
}

Output

Java Tutorials