home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book Home Java Enterprise in a Nutshell Search this book

2.3. Properties

Every AWT and Swing component can have its appearance and behavior customized by specifying values for its properties. In Example 2-1, we set the text property of the JButton components by calling the setText() method and the border property of the JLabel by calling setBorder().

The properties of a component are not a formal part of a Java class, in the way that the fields and methods of a class are. Instead, the notion of properties is merely a naming convention adopted from the JavaBeans component framework. When a component defines a pair of public accessor methods whose names begin with "set" and "get", this pair of methods defines a property. For example, the methods setFont() and getFont() define the font property of a component. When a property is of type boolean, the "get" accessor method is often replaced with one that begins with "is". For example, the setVisible() and isVisible() methods define the visible property.

Although any given component may define only a few properties of its own, every component inherits the properties of its superclasses. If you refer to the reference pages for JComponent, Component, and MenuComponent, you'll see that there are quite a few of these inherited properties.

Thinking about GUI components in terms of the properties they define and the properties they inherit is useful because it conveniently sums up the customizable state of the component. Looking at a list of component properties tells you a lot about what you can do with the component. This is so useful, in fact, that the reference section of this book groups property accessor methods separately from other methods.

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.