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 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.