Chapter 5. Buttons
Buttons are simple UI components used to generate events
when the user presses them. Swing buttons can display icons, text, or both. In this section, we’ll introduce the ButtonModel
interface and DefaultButtonModel
class (which define the state
of the button). Next, we’ll look at the AbstractButton
class (which defines much of the
functionality for all button types). Finally, we’ll look at four concrete
subclasses of AbstractButton
and see
how they can be grouped together using a ButtonGroup
.
Figure 5-1 shows the
class hierarchy, with significant relationships between the
button-related Swing classes. As we discussed in the introductory
chapters, each button (AbstractButton
)
keeps a reference to a ButtonModel
,
which represents its state.
Figure 5-1. Button class diagram
The JMenuItem
class shown here
(and its subclasses, not shown) is not covered in this chapter; see Chapter 14 for details.
Get Java Swing, 2nd 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.