14.13. Other Simple Swing Components

Finally, we'll very briefly mention a couple of other simple Swing components that map to AWT equivalents: JCheckBox, JRadioButton, JTextField, and JTextArea. In addition, we'll briefly cover JFileChooser for opening a dialog to select files. For additional information on these topics, please see Core Java Foundation Classes by Kim Topley.

The JCheckBox Component

JCheckBox is similar to Checkbox (but note the capital B in JCheckBox). You can attach either an ActionListener or an ItemListener to monitor events. If you use an ActionListener, you'll want to call isSelected to distinguish a selection from a deselection. If you use an ItemListener, the ItemEvent itself has information regarding the selection state: ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.