Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click here for Oracle 8i Internet Seminars.
Click here for Oracle 8i Internet Seminars.
ITKnowledge
Find:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


A separate icon can be specified for use when the label is disabled. Because an instance of the JLabel class cannot acquire input focus, the exact definition of a disabled label is somewhat vague. However, the JLabel class is a descendant from the AWT Component class, so it can be enabled and disabled with the setEnabled method. If an icon has been specified by using the setDisabledIcon method, this icon will be drawn when the label is disabled. If a disabled icon has not been specified and an icon has been specified, a disabled icon will be created with the GrayFilter class previously described.

When creating user interfaces, a label is often used in conjunction with another component. For example, a label is used to describe the data to be entered into a text field in a form display. The JLabel class contains two methods that work in tandem and specify a mnemonic and an associated component for the label. When the mnemonic is activated, the input focus is requested for the associated component. The setDisplayedMnemonic method is used to set the mnemonic for the label. A character or keycode can be passed to this method. The setLabelFor method specifies the component that is to receive focus when the mnemonic is activated. Both properties must be set with non-null values for this behavior to be active. These are both bound properties, named labelFor and displayedMnemonic, respectively. The current value for the properties can be queried with the getLabelFor and getDisplayedMnemonic methods. In the setLabelFor method, if the associated component is a descendant of the JComponent class, the label sets itself as the labeledBy client property of the component. This allows the component to check if a label has been set for it.

The previous paragraphs presented the bound properties contained in the JLabel class. Table 5.1 summarizes these properties. The Swing visual components are JavaBean- compliant, and the property setter and getter methods conform to the Bean property naming convention. There are not constants defined for the property names at the current time. The property names are hard coded in the JFC source code. If you find that a listener is not receiving a property notification when you think it should, make sure you do not have a typo in the property name. The compiler could perform this type of check for you if the names were defined as constants. This is an unfortunate situation that hopefully will be rectified in the future. As you will see in the next chapter, these properties are also available for the buttons contained in the JFC.

Table 5.1 JLabel Class Bound Properties

Property Name Setter Method Getter Method

Text setText getText
Icon setIcon getIcon
DisabledIcon setDisabledIcon getDisabledIcon
DisplayedMnemonic setDisplayedMnemonic getDisplayedMnemonic
Opaque setOpaque
IconTextGap setIconTextGap getIconTextGap
VerticalAlignment setVerticalAlignment getVerticalAlignment
HorizontalAlignment setHorizontalAlignment getHorizontalAlignment
HorizontalTextPosition setHorizontalTextPosition getHorizontalTextPosition
VerticalTextPosition setVerticalTextPosition getVerticalTextPosition
LabelFor setLabelFor getLabelFor

Summary

This chapter presented the basic components contained in the JFC. Borders provide a means of grouping other components and adding interesting visuals. The JFC contains the BorderFactory class that is used to create a border. The Icon interface and ImageIcon class were presented for bitmap graphic manipulation. Labels are used in many user interface situations. The JLabel class addressed one of the limitations of the AWT, an easy component with which to display images. Instances of the JLabel class can contain text and an icon. The methods for placing the text and icon were presented. A label can have a mnemonic and a component associated with it. When the mnemonic is activated, the label will request the input focus for the associated component.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.