java.awt

Class Label

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class Label
extends Component
implements Accessible

This component is used for displaying simple text strings that cannot be edited by the user.
See Also:
Serialized Form

Nested Class Summary

protected class
Label.AccessibleAWTLabel
This class provides accessibility support for the label.

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

static int
CENTER
Alignment constant aligning the text in the center of its window.
static int
LEFT
Alignment constant aligning the text to the left of its window.
static int
RIGHT
Alignment constant aligning the text to the right of its window.

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

Label()
Initializes a new instance of Label with no text.
Label(String text)
Initializes a new instance of Label with the specified text that is aligned to the left.
Label(String text, int alignment)
Initializes a new instance of Label with the specified text and alignment.

Method Summary

void
addNotify()
Notifies this label that it has been added to a container, causing the peer to be created.
AccessibleContext
getAccessibleContext()
Gets the AccessibleContext associated with this Label.
int
getAlignment()
Returns the constant indicating the alignment of the text in this label.
String
getText()
Returns the text displayed in this label.
protected String
paramString()
Returns a parameter string useful for debugging.
void
setAlignment(int alignment)
Sets the text alignment of this label to the specified value.
void
setText(String text)
Sets the text in this label to the specified value.

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

CENTER

public static final int CENTER
Alignment constant aligning the text in the center of its window.
Field Value:
1

LEFT

public static final int LEFT
Alignment constant aligning the text to the left of its window.
Field Value:
0

RIGHT

public static final int RIGHT
Alignment constant aligning the text to the right of its window.
Field Value:
2

Constructor Details

Label

public Label()
Initializes a new instance of Label with no text.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Label

public Label(String text)
Initializes a new instance of Label with the specified text that is aligned to the left.
Parameters:
text - The text of the label.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Label

public Label(String text,
             int alignment)
Initializes a new instance of Label with the specified text and alignment.
Parameters:
text - The text of the label.
alignment - The desired alignment for the text in this label, which must be one of LEFT, CENTER, or RIGHT.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() is true.

Method Details

addNotify

public void addNotify()
Notifies this label that it has been added to a container, causing the peer to be created. This method is called internally by the AWT system.
Overrides:
addNotify in interface Component

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Label. The context is created, if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface Component
Returns:
the associated context

getAlignment

public int getAlignment()
Returns the constant indicating the alignment of the text in this label. The value returned will be one of the alignment constants from this class.
Returns:
The alignment of the text in the label.

getText

public String getText()
Returns the text displayed in this label.
Returns:
The text for this label.

paramString

protected String paramString()
Returns a parameter string useful for debugging.
Overrides:
paramString in interface Component
Returns:
A debugging string.

setAlignment

public void setAlignment(int alignment)
Sets the text alignment of this label to the specified value.
Parameters:
alignment - The desired alignment for the text in this label, which must be one of LEFT, CENTER, or RIGHT.

setText

public void setText(String text)
Sets the text in this label to the specified value.
Parameters:
text - The new text for this label.

Label.java -- Java label widget Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.