Java tutorial
import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JComboBox; import javax.swing.JFrame; public class Main { public static void main(String[] args) { JComboBox<String> box = new JComboBox<>(); box.addItem("One"); box.addItem("Two"); box.addItem("Three"); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { System.out.println(e.getItem()); } } }); JFrame frame = new JFrame(); frame.getContentPane().add(box); frame.pack(); frame.setVisible(true); } }