12.11 JComboBox; Using an Anonymous Inner Class for Event Handling

A combo box (sometimes called a drop-down list) enables the user to select one item from a list (Fig. 12.22). Combo boxes are implemented with class JComboBox, which extends class JComponent. JComboBox is a generic class, like the class ArrayList (Chapter 7). When you create a JComboBox, you specify the type of the objects that it manages—the JComboBox then displays a String representation of each object.

 1   // Fig. 12.21: ComboBoxFrame.java 2   // JComboBox that displays a list of image names. 3   import java.awt.FlowLayout; 4   import java.awt.event.ItemListener; 5   import java.awt.event.ItemEvent; 6   import javax.swing.JFrame; 7   import ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.