Working with Components

Swing offers more than two dozen different user interface components in addition to the buttons and containers you have used thus far. You will work with many of these components for the rest of the day and on Day 9, "Building a Swing Interface."

All Swing components share a common superclass, javax.swing.JComponent, and inherit several methods you will find useful in your own programs.

The setEnabled(boolean) method enables a component if the argument is true and disables it if the argument is false. Components are enabled by default, and they must be enabled in order to receive user input. Many disabled components will change in appearance to indicate that they are not presently usable—for instance, a disabled JButton ...

Get Sams Teach Yourself Java 2 in 21 Days, 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.