JComboBox Example Java Swing

JComboBox Example Java Swing

A JComboBox (sometimes called a drop-down list) provides a list of items from which the user can make a selection.

Combo boxes are implemented with class JComboBox, which inherits from class JComponent. JComboBox generates ItemEvent like JCheckBox and JRadioButton. Its counterpart in AWT is Choice.

In the following JComboBox example a combo box and text field are added to JFrame. User’s selection of item in the combo box is displayed in the text field. To catch the events generated by items of combo box, a separate helper class is created (generally we write GUI and event handling code in a single program). Always in projects, event handling mechanism is written separately in a class as in the following program. Observe that the text field is passed as a parameter to the helper class. This is the way to create a link between the helper class and the main class components.


JComboBox
Output screen of JComboBox Example