java.awt
Class Label
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Label
-
- All Implemented Interfaces:
- java.awt.image.ImageObserver, MenuContainer, java.io.Serializable, javax.accessibility.Accessible
public class Label extends Component implements javax.accessibility.AccessibleALabel
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.For example, the code . . .
setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); add(new Label("Hi There!")); add(new Label("Another Label"));
produces the following labels:
- Since:
- JDK1.0
- See Also:
- Serialized Form
-
-
Nested Classes Modifier and Type Class and Description AccessibleAWTComponent Inner class of Component used to provide default support for accessibility.BaselineResizeBehavior Enumeration of the common ways the baseline of a component can change as the size changes.BltBufferStrategy Inner class for blitting offscreen surfaces to a component.FlipBufferStrategy Inner class for flipping buffers on a component.AccessibleAWTLabel This class implements accessibility support for theLabel
class.
-
Fields Modifier and Type Field and Description ABORT This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously was aborted before production was complete.ALLBITS This flag in the infoflags argument to imageUpdate indicates that a static image which was previously drawn is now complete and can be drawn again in its final form.BOTTOM_ALIGNMENT Ease-of-use constant forgetAlignmentY
.CENTER Indicates that the label should be centered.CENTER_ALIGNMENT Ease-of-use constant forgetAlignmentY
andgetAlignmentX
.ERROR This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously has encountered an error.FRAMEBITS This flag in the infoflags argument to imageUpdate indicates that another complete frame of a multi-frame image which was previously drawn is now available to be drawn again.HEIGHT This flag in the infoflags argument to imageUpdate indicates that the height of the base image is now available and can be taken from the height argument to the imageUpdate callback method.LEFT Indicates that the label should be left justified.LEFT_ALIGNMENT Ease-of-use constant forgetAlignmentX
.PROPERTIES This flag in the infoflags argument to imageUpdate indicates that the properties of the image are now available.RIGHT Indicates that the label should be right justified.RIGHT_ALIGNMENT Ease-of-use constant forgetAlignmentX
.SOMEBITS This flag in the infoflags argument to imageUpdate indicates that more pixels needed for drawing a scaled variation of the image are available.TOP_ALIGNMENT Ease-of-use constant forgetAlignmentY()
.WIDTH This flag in the infoflags argument to imageUpdate indicates that the width of the base image is now available and can be taken from the width argument to the imageUpdate callback method.
-
-
Basic Attribute Methods Modifier and Type Method and Description applyComponentOrientation Sets theComponentOrientation
property of this component and all components contained within it.disable Deprecated. As of JDK version 1.1, replaced bysetEnabled(boolean)
.enable Deprecated. As of JDK version 1.1, replaced bysetEnabled(boolean)
.enable Deprecated. As of JDK version 1.1, replaced bysetEnabled(boolean)
.enableInputMethods Enables or disables input method support for this component.getAccessibleContext Gets the AccessibleContext associated with this Label.getBackground Gets the background color of this component.getColorModel Gets the instance ofColorModel
used to display the component on the output device.getComponentOrientation Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component.getCursor Gets the cursor set in the component.getFont Gets the font of this component.getForeground Gets the foreground color of this component.getLocale Gets the locale of this component.getName Gets the name of the component.getParent Gets the parent of this component.hide Deprecated. As of JDK version 1.1, replaced bysetVisible(boolean)
.isBackgroundSet Returns whether the background color has been explicitly set for this Component.isCursorSet Returns whether the cursor has been explicitly set for this Component.isDisplayable Determines whether this component is displayable.isDoubleBuffered Returns true if this component is painted to an offscreen image ("buffer") that's copied to the screen later.isEnabled Determines whether this component is enabled.isFontSet Returns whether the font has been explicitly set for this Component.isForegroundSet Returns whether the foreground color has been explicitly set for this Component.isLightweight A lightweight component doesn't have a native toolkit peer.isOpaque Returns true if this component is completely opaque, returns false by default.isShowing Determines whether this component is showing on screen.isVisible Determines whether this component should be visible when its parent is visible.setBackground Sets the background color of this component.setComponentOrientation Sets the language-sensitive orientation that is to be used to order the elements or text within this component.setCursor Sets the cursor image to the specified cursor.setEnabled Enables or disables this component, depending on the value of the parameterb
.setFont Sets the font of this component.setForeground Sets the foreground color of this component.setLocale Sets the locale of this component.setName Sets the name of the component to the specified string.setVisible Shows or hides this component depending on the value of parameterb
.show Deprecated. As of JDK version 1.1, replaced bysetVisible(boolean)
.show Deprecated. As of JDK version 1.1, replaced bysetVisible(boolean)
. -
Event Support Methods Modifier and Type Method and Description action Deprecated. As of JDK version 1.1, should register this component as ActionListener on component which fires action events.coalesceEvents Potentially coalesce an event being posted with an existing event.deliverEvent Deprecated. As of JDK version 1.1, replaced bydispatchEvent(AWTEvent e)
.disableEvents Disables the events defined by the specified event mask parameter from being delivered to this component.dispatchEvent Dispatches an event to this component or one of its sub components.enableEvents Enables the events defined by the specified event mask parameter to be delivered to this component.firePropertyChange Support for reporting bound property changes for boolean properties.firePropertyChange Reports a bound property change.firePropertyChange Reports a bound property change.firePropertyChange Reports a bound property change.firePropertyChange Reports a bound property change.firePropertyChange Support for reporting bound property changes for integer properties.firePropertyChange Reports a bound property change.firePropertyChange Support for reporting bound property changes for Object properties.firePropertyChange Reports a bound property change.getListeners Returns an array of all the objects currently registered asFooListener
s upon thisComponent
.handleEvent Deprecated. As of JDK version 1.1 replaced by processEvent(AWTEvent).keyDown Deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).keyUp Deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).mouseDown Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).mouseDrag Deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).mouseEnter Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).mouseExit Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).mouseMove Deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).mouseUp Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).postEvent Deprecated. As of JDK version 1.1, replaced by dispatchEvent(AWTEvent).processComponentEvent Processes component events occurring on this component by dispatching them to any registeredComponentListener
objects.processEvent Processes events occurring on this component.processFocusEvent Processes focus events occurring on this component by dispatching them to any registeredFocusListener
objects.processHierarchyBoundsEvent Processes hierarchy bounds events occurring on this component by dispatching them to any registeredHierarchyBoundsListener
objects.processHierarchyEvent Processes hierarchy events occurring on this component by dispatching them to any registeredHierarchyListener
objects.processInputMethodEvent Processes input method events occurring on this component by dispatching them to any registeredInputMethodListener
objects.processKeyEvent Processes key events occurring on this component by dispatching them to any registeredKeyListener
objects.processMouseEvent Processes mouse events occurring on this component by dispatching them to any registeredMouseListener
objects.processMouseMotionEvent Processes mouse motion events occurring on this component by dispatching them to any registeredMouseMotionListener
objects.processMouseWheelEvent Processes mouse wheel events occurring on this component by dispatching them to any registeredMouseWheelListener
objects. -
Event Registration Methods Modifier and Type Method and Description addComponentListener Adds the specified component listener to receive component events from this component.addFocusListener Adds the specified focus listener to receive focus events from this component when this component gains input focus.addHierarchyBoundsListener Adds the specified hierarchy bounds listener to receive hierarchy bounds events from this component when the hierarchy to which this container belongs changes.addHierarchyListener Adds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes.addInputMethodListener Adds the specified input method listener to receive input method events from this component.addKeyListener Adds the specified key listener to receive key events from this component.addMouseListener Adds the specified mouse listener to receive mouse events from this component.addMouseMotionListener Adds the specified mouse motion listener to receive mouse motion events from this component.addMouseWheelListener Adds the specified mouse wheel listener to receive mouse wheel events from this component.addPropertyChangeListener Adds a PropertyChangeListener to the listener list.addPropertyChangeListener Adds a PropertyChangeListener to the listener list for a specific property.getComponentListeners Returns an array of all the component listeners registered on this component.getFocusListeners Returns an array of all the focus listeners registered on this component.getHierarchyBoundsListeners Returns an array of all the hierarchy bounds listeners registered on this component.getHierarchyListeners Returns an array of all the hierarchy listeners registered on this component.getInputMethodListeners Returns an array of all the input method listeners registered on this component.getKeyListeners Returns an array of all the key listeners registered on this component.getMouseListeners Returns an array of all the mouse listeners registered on this component.getMouseMotionListeners Returns an array of all the mouse motion listeners registered on this component.getMouseWheelListeners Returns an array of all the mouse wheel listeners registered on this component.getPropertyChangeListeners Returns an array of all the property change listeners registered on this component.getPropertyChangeListeners Returns an array of all the listeners which have been associated with the named property.removeComponentListener Removes the specified component listener so that it no longer receives component events from this component.removeFocusListener Removes the specified focus listener so that it no longer receives focus events from this component.removeHierarchyBoundsListener Removes the specified hierarchy bounds listener so that it no longer receives hierarchy bounds events from this component.removeHierarchyListener Removes the specified hierarchy listener so that it no longer receives hierarchy changed events from this component.removeInputMethodListener Removes the specified input method listener so that it no longer receives input method events from this component.removeKeyListener Removes the specified key listener so that it no longer receives key events from this component.removeMouseListener Removes the specified mouse listener so that it no longer receives mouse events from this component.removeMouseMotionListener Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component.removeMouseWheelListener Removes the specified mouse wheel listener so that it no longer receives mouse wheel events from this component.removePropertyChangeListener Removes a PropertyChangeListener from the listener list.removePropertyChangeListener Removes aPropertyChangeListener
from the listener list for a specific property. -
Keyboard Focus Methods Modifier and Type Method and Description areFocusTraversalKeysSet Returns whether the Set of focus traversal keys for the given focus traversal operation has been explicitly defined for this Component.getFocusCycleRootAncestor Returns the Container which is the focus cycle root of this Component's focus traversal cycle.getFocusTraversalKeys Returns the Set of focus traversal keys for a given traversal operation for this Component.getFocusTraversalKeysEnabled Returns whether focus traversal keys are enabled for this Component.gotFocus Deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).hasFocus Returnstrue
if thisComponent
is the focus owner.isFocusable Returns whether this Component can be focused.isFocusCycleRoot Returns whether the specified Container is the focus cycle root of this Component's focus traversal cycle.isFocusOwner Returnstrue
if thisComponent
is the focus owner.isFocusTraversable Deprecated. As of 1.4, replaced byisFocusable()
.lostFocus Deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).nextFocus Deprecated. As of JDK version 1.1, replaced by transferFocus().requestFocus Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window.requestFocus Requests that thisComponent
get the input focus, and that thisComponent
's top-level ancestor become the focusedWindow
.requestFocusInWindow Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window.requestFocusInWindow Requests that thisComponent
get the input focus, if thisComponent
's top-level ancestor is already the focusedWindow
.setFocusable Sets the focusable state of this Component to the specified value.setFocusTraversalKeys Sets the focus traversal keys for a given traversal operation for this Component.setFocusTraversalKeysEnabled Sets whether focus traversal keys are enabled for this Component.transferFocus Transfers the focus to the next component, as though this Component were the focus owner.transferFocusBackward Transfers the focus to the previous component, as though this Component were the focus owner.transferFocusUpCycle Transfers the focus up one focus traversal cycle. -
Graphics Methods Modifier and Type Method and Description getFontMetrics Gets the font metrics for the specified font.getGraphics Creates a graphics context for this component.getGraphicsConfiguration Gets theGraphicsConfiguration
associated with thisComponent
.getLocationOnScreen Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.getMousePosition Returns the position of the mouse pointer in thisComponent
's coordinate space if theComponent
is directly under the mouse pointer, otherwise returnsnull
.getToolkit Gets the toolkit of this component. -
Image Methods Modifier and Type Method and Description checkImage Returns the status of the construction of a screen representation of the specified image.checkImage Returns the status of the construction of a screen representation of the specified image.createImage Creates an image from the specified image producer.createImage Creates an off-screen drawable image to be used for double buffering.createVolatileImage Creates a volatile off-screen drawable image to be used for double buffering.createVolatileImage Creates a volatile off-screen drawable image, with the given capabilities.imageUpdate Repaints the component when the image has changed.prepareImage Prepares an image for rendering on this component.prepareImage Prepares an image for rendering on this component at the specified width and height. -
Layout Methods Modifier and Type Method and Description bounds Deprecated. As of JDK version 1.1, replaced bygetBounds()
.contains Checks whether this component "contains" the specified point, wherex
andy
are defined to be relative to the coordinate system of this component.contains Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component.doLayout Prompts the layout manager to lay out this component.getAlignmentX Returns the alignment along the x axis.getAlignmentY Returns the alignment along the y axis.getBaseline Returns the baseline.getBaselineResizeBehavior Returns an enum indicating how the baseline of the component changes as the size changes.getBounds Gets the bounds of this component in the form of aRectangle
object.getBounds Stores the bounds of this component into "return value" rv and return rv.getComponentAt Determines if this component or one of its immediate subcomponents contains the (x, y) location, and if so, returns the containing component.getComponentAt Returns the component or subcomponent that contains the specified point.getHeight Returns the current height of this component.getLocation Gets the location of this component in the form of a point specifying the component's top-left corner.getLocation Stores the x,y origin of this component into "return value" rv and return rv.getMaximumSize Gets the maximum size of this component.getMinimumSize Gets the mininimum size of this component.getPreferredSize Gets the preferred size of this component.getSize Returns the size of this component in the form of aDimension
object.getSize Stores the width/height of this component into "return value" rv and return rv.getWidth Returns the current width of this component.getX Returns the current x coordinate of the components origin.getY Returns the current y coordinate of the components origin.inside Deprecated. As of JDK version 1.1, replaced by contains(int, int).invalidate Invalidates this component and its ancestors.isMaximumSizeSet Returns true if the maximum size has been set to a non-null
value otherwise returns false.isMinimumSizeSet Returns whether or notsetMinimumSize
has been invoked with a non-null value.isPreferredSizeSet Returns true if the preferred size has been set to a non-null
value otherwise returns false.isValid Determines whether this component is valid.layout Deprecated. As of JDK version 1.1, replaced bydoLayout()
.locate Deprecated. As of JDK version 1.1, replaced by getComponentAt(int, int).location Deprecated. As of JDK version 1.1, replaced bygetLocation()
.minimumSize Deprecated. As of JDK version 1.1, replaced bygetMinimumSize()
.move Deprecated. As of JDK version 1.1, replaced bysetLocation(int, int)
.preferredSize Deprecated. As of JDK version 1.1, replaced bygetPreferredSize()
.reshape Deprecated. As of JDK version 1.1, replaced bysetBounds(int, int, int, int)
.resize Deprecated. As of JDK version 1.1, replaced bysetSize(Dimension)
.resize Deprecated. As of JDK version 1.1, replaced bysetSize(int, int)
.revalidate Revalidates the component hierarchy up to the nearest validate root.setBounds Moves and resizes this component.setBounds Moves and resizes this component to conform to the new bounding rectangler
.setLocation Moves this component to a new location.setLocation Moves this component to a new location.setMaximumSize Sets the maximum size of this component to a constant value.setMinimumSize Sets the minimum size of this component to a constant value.setPreferredSize Sets the preferred size of this component to a constant value.setSize Resizes this component so that it has widthd.width
and heightd.height
.setSize Resizes this component so that it has widthwidth
and heightheight
.size Deprecated. As of JDK version 1.1, replaced bygetSize()
.validate Validates this component. -
Painting Methods Modifier and Type Method and Description getIgnoreRepaint paint Paints this component.paintAll Paints this component and all of its subcomponents.repaint Repaints this component.repaint Repaints the specified rectangle of this component.repaint Repaints the component.repaint Repaints the specified rectangle of this component withintm
milliseconds.setIgnoreRepaint Sets whether or not paint messages received from the operating system should be ignored.update Updates this component. -
Printing Methods Modifier and Type Method and Description list Prints a listing of this component to the standard system output streamSystem.out
.list Prints a listing of this component to the specified output stream.list Prints out a list, starting at the specified indentation, to the specified print stream.list Prints a listing to the specified print writer.list Prints out a list, starting at the specified indentation, to the specified print writer.print Prints this component.printAll Prints this component and all of its subcomponents. -
Other Methods Modifier and Type Method and Description add Adds the specified popup menu to the component.addNotify Creates the peer for this label.getAlignment Gets the current alignment of this label.getDropTarget Gets theDropTarget
associated with thisComponent
.getInputContext Gets the input context used by this component for handling the communication with input methods when text is entered in this component.getInputMethodRequests Gets the input method request handler which supports requests from input methods for this component.getPeer Deprecated. As of JDK version 1.1, programs should not directly manipulate peers; replaced byboolean isDisplayable()
.getText Gets the text of this label.getTreeLock Gets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.paramString Returns a string representing the state of thisLabel
.remove Removes the specified popup menu from the component.removeNotify Makes thisComponent
undisplayable by destroying it native screen resource.setAlignment Sets the alignment for this label to the specified alignment.setDropTarget Associate aDropTarget
with this component.setText Sets the text for this label to the specified text.toString Returns a string representation of this component and its values.
-
-