- Class JLabel
- Class Label
- Nested Class Summary
- Nested classes/interfaces declared in class java.awt.Component
- Field Summary
- Fields declared in class java.awt.Component
- Fields declared in interface java.awt.image.ImageObserver
- Constructor Summary
- Method Summary
- Methods declared in class java.awt.Component
- Methods declared in class java.lang.Object
- Field Details
- LEFT
- CENTER
- RIGHT
- Constructor Details
- Label
- Label
- Label
- Method Details
- addNotify
- getAlignment
- setAlignment
- getText
- setText
- paramString
- getAccessibleContext
- Class JLabel
- Class Label
- Nested Class Summary
- Nested classes/interfaces declared in class java.awt.Component
- Field Summary
- Fields declared in class java.awt.Component
- Fields declared in interface java.awt.image.ImageObserver
- Constructor Summary
- Method Summary
- Methods declared in class java.awt.Component
- Methods declared in class java.lang.Object
- Field Details
- LEFT
- CENTER
- RIGHT
- Constructor Details
- Label
- Label
- Label
- Method Details
- addNotify
- getAlignment
- setAlignment
- getText
- setText
- paramString
- getAccessibleContext
Class JLabel
A display area for a short text string or an image, or both. A label does not react to input events. As a result, it cannot get the keyboard focus. A label can, however, display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can’t display it.
A JLabel object can display either text, an image, or both. You can specify where in the label’s display area the label’s contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default.
You can also specify the position of the text relative to the image. By default, text is on the trailing edge of the image, with the text and image vertically aligned.
A label’s leading and trailing edge are determined from the value of its ComponentOrientation property. At present, the default ComponentOrientation setting maps the leading edge to left and the trailing edge to right.
Finally, you can use the setIconTextGap method to specify how many pixels should appear between the text and the image. The default is 4 pixels.
See How to Use Labels in The Java Tutorial for further documentation.
Warning: Swing is not thread safe. For more information see Swing’s Threading Policy.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder .
Class Label
A Label object is a component for placing text in a container. A label displays a single line of read-only text. The text can be changed by the application, but a user cannot edit it directly.
setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); add(new Label("Hi There!")); add(new Label("Another Label"));
produces the following labels:
Nested Class Summary
Nested classes/interfaces declared in class java.awt.Component
Field Summary
Fields declared in class java.awt.Component
Fields declared in interface java.awt.image.ImageObserver
Constructor Summary
Method Summary
Methods declared in class java.awt.Component
Methods declared in class java.lang.Object
Field Details
LEFT
CENTER
RIGHT
Constructor Details
Label
Label
Label
Constructs a new label that presents the specified string of text with the specified alignment. Possible values for alignment are Label.LEFT , Label.RIGHT , and Label.CENTER .
Method Details
addNotify
Creates the peer for this label. The peer allows us to modify the appearance of the label without changing its functionality.
getAlignment
Gets the current alignment of this label. Possible values are Label.LEFT , Label.RIGHT , and Label.CENTER .
setAlignment
Sets the alignment for this label to the specified alignment. Possible values are Label.LEFT , Label.RIGHT , and Label.CENTER .
getText
setText
paramString
Returns a string representing the state of this Label . This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null .
getAccessibleContext
Gets the AccessibleContext associated with this Label. For labels, the AccessibleContext takes the form of an AccessibleAWTLabel. A new AccessibleAWTLabel instance is created if necessary.
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Class JLabel
A display area for a short text string or an image, or both. A label does not react to input events. As a result, it cannot get the keyboard focus. A label can, however, display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can’t display it.
A JLabel object can display either text, an image, or both. You can specify where in the label’s display area the label’s contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default.
You can also specify the position of the text relative to the image. By default, text is on the trailing edge of the image, with the text and image vertically aligned.
A label’s leading and trailing edge are determined from the value of its ComponentOrientation property. At present, the default ComponentOrientation setting maps the leading edge to left and the trailing edge to right.
Finally, you can use the setIconTextGap method to specify how many pixels should appear between the text and the image. The default is 4 pixels.
See How to Use Labels in The Java Tutorial for further documentation.
Warning: Swing is not thread safe. For more information see Swing’s Threading Policy.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder .
Class Label
A Label object is a component for placing text in a container. A label displays a single line of read-only text. The text can be changed by the application, but a user cannot edit it directly.
setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); add(new Label("Hi There!")); add(new Label("Another Label"));
produces the following labels:
Nested Class Summary
Nested classes/interfaces declared in class java.awt.Component
Field Summary
Fields declared in class java.awt.Component
Fields declared in interface java.awt.image.ImageObserver
Constructor Summary
Method Summary
Methods declared in class java.awt.Component
Methods declared in class java.lang.Object
Field Details
LEFT
CENTER
RIGHT
Constructor Details
Label
Label
Label
Constructs a new label that presents the specified string of text with the specified alignment. Possible values for alignment are Label.LEFT , Label.RIGHT , and Label.CENTER .
Method Details
addNotify
Creates the peer for this label. The peer allows us to modify the appearance of the label without changing its functionality.
getAlignment
Gets the current alignment of this label. Possible values are Label.LEFT , Label.RIGHT , and Label.CENTER .
setAlignment
Sets the alignment for this label to the specified alignment. Possible values are Label.LEFT , Label.RIGHT , and Label.CENTER .
getText
setText
paramString
Returns a string representing the state of this Label . This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null .
getAccessibleContext
Gets the AccessibleContext associated with this Label. For labels, the AccessibleContext takes the form of an AccessibleAWTLabel. A new AccessibleAWTLabel instance is created if necessary.
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.