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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access