Save This Page
Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: Label [javadoc | source]
java.lang.Object
   java.awt.Component
      java.awt.Label

All Implemented Interfaces:
    Accessible, MenuContainer, Serializable, ImageObserver

Direct Known Subclasses:
   

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.

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:

Two labels: 'Hi There!' and 'Another label'

Nested Class Summary:
protected class  Label.AccessibleAWTLabel  This class implements accessibility support for the Label class. It provides an implementation of the Java Accessibility API appropriate to label user-interface elements. 
Field Summary
public static final  int LEFT    Indicates that the label should be left justified. 
public static final  int CENTER    Indicates that the label should be centered. 
public static final  int RIGHT    Indicates that the label should be right justified.
    since: JDK1.0t. -
 
 String text    The text of this label. This text can be modified by the program but never by the user. 
 int alignment    The label's alignment. The default alignment is set to be left justified. 
Fields inherited from java.awt.Component:
peer,  parent,  appContext,  x,  y,  width,  height,  foreground,  background,  font,  peerFont,  cursor,  locale,  bufferStrategy,  ignoreRepaint,  visible,  enabled,  dropTarget,  popups,  focusTraversalKeys,  LOCK,  minSize,  minSizeSet,  prefSize,  prefSizeSet,  maxSize,  maxSizeSet,  componentOrientation,  newEventsOnly,  componentListener,  focusListener,  hierarchyListener,  hierarchyBoundsListener,  keyListener,  mouseListener,  mouseMotionListener,  mouseWheelListener,  inputMethodListener,  windowClosingException,  actionListenerK,  adjustmentListenerK,  componentListenerK,  containerListenerK,  focusListenerK,  itemListenerK,  keyListenerK,  mouseListenerK,  mouseMotionListenerK,  mouseWheelListenerK,  textListenerK,  ownedWindowK,  windowListenerK,  inputMethodListenerK,  hierarchyListenerK,  hierarchyBoundsListenerK,  windowStateListenerK,  windowFocusListenerK,  eventMask,  isInc,  incRate,  TOP_ALIGNMENT,  CENTER_ALIGNMENT,  BOTTOM_ALIGNMENT,  LEFT_ALIGNMENT,  RIGHT_ALIGNMENT,  isPacked,  backgroundEraseDisabled,  eventCache,  accessibleContext
Constructor:
 public Label() throws HeadlessException 
    Constructs an empty label. The text of the label is the empty string "".
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
 public Label(String text) throws HeadlessException 
    Constructs a new label with the specified string of text, left justified.
    Parameters:
    text - the string that the label presents. A null value will be accepted without causing a NullPointerException to be thrown.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
 public Label(String text,
    int alignment) throws HeadlessException 
    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.
    Parameters:
    text - the string that the label presents. A null value will be accepted without causing a NullPointerException to be thrown.
    alignment - the alignment value.
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    exception: HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Method from java.awt.Label Summary:
addNotify,   constructComponentName,   getAccessibleContext,   getAlignment,   getText,   paramString,   setAlignment,   setText
Methods from java.awt.Component:
action,   add,   addComponentListener,   addFocusListener,   addHierarchyBoundsListener,   addHierarchyListener,   addInputMethodListener,   addKeyListener,   addMouseListener,   addMouseMotionListener,   addMouseWheelListener,   addNotify,   addPropertyChangeListener,   addPropertyChangeListener,   adjustListeningChildrenOnParent,   applyComponentOrientation,   applyCompoundShape,   applyCurrentShape,   areBoundsValid,   areFocusTraversalKeysSet,   areInputMethodsEnabled,   autoProcessMouseWheel,   bounds,   canBeFocusOwner,   canBeFocusOwnerRecursively,   checkGD,   checkImage,   checkImage,   checkTreeLock,   checkWindowClosingException,   clearCurrentFocusCycleRootOnHide,   clearMostRecentFocusOwnerOnHide,   coalesceEvents,   constructComponentName,   contains,   contains,   containsFocus,   countHierarchyMembers,   createBufferStrategy,   createBufferStrategy,   createHierarchyEvents,   createImage,   createImage,   createVolatileImage,   createVolatileImage,   deliverEvent,   disable,   disableEvents,   dispatchEvent,   dispatchEventImpl,   dispatchMouseWheelToAncestor,   doLayout,   enable,   enable,   enableEvents,   enableInputMethods,   eventEnabled,   eventTypeEnabled,   findUnderMouseInWindow,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   getAccessControlContext,   getAccessibleContext,   getAccessibleIndexInParent,   getAccessibleStateSet,   getAlignmentX,   getAlignmentY,   getBackBuffer,   getBackground,   getBaseline,   getBaselineResizeBehavior,   getBounds,   getBounds,   getBoundsOp,   getBufferStrategy,   getColorModel,   getComponentAt,   getComponentAt,   getComponentListeners,   getComponentOrientation,   getContainer,   getContainingWindow,   getCursor,   getCursor_NoClientCode,   getDropTarget,   getFocusCycleRootAncestor,   getFocusListeners,   getFocusTraversalKeys,   getFocusTraversalKeysEnabled,   getFocusTraversalKeys_NoIDCheck,   getFont,   getFontMetrics,   getFont_NoClientCode,   getForeground,   getGraphics,   getGraphicsConfiguration,   getGraphicsConfiguration_NoClientCode,   getGraphics_NoClientCode,   getHWPeerAboveMe,   getHeight,   getHierarchyBoundsListeners,   getHierarchyListeners,   getIgnoreRepaint,   getInputContext,   getInputMethodListeners,   getInputMethodRequests,   getKeyListeners,   getListeners,   getLocale,   getLocation,   getLocation,   getLocationOnScreen,   getLocationOnScreen_NoTreeLock,   getLocationOnWindow,   getMaximumSize,   getMinimumSize,   getMouseListeners,   getMouseMotionListeners,   getMousePosition,   getMouseWheelListeners,   getName,   getNativeContainer,   getNextFocusCandidate,   getNormalShape,   getObjectLock,   getOpaqueShape,   getParent,   getParent_NoClientCode,   getPeer,   getPreferredSize,   getPropertyChangeListeners,   getPropertyChangeListeners,   getSiblingIndexAbove,   getSiblingIndexBelow,   getSize,   getSize,   getToolkit,   getToolkitImpl,   getTraversalRoot,   getTreeLock,   getWidth,   getX,   getY,   gotFocus,   handleEvent,   hasFocus,   hide,   imageUpdate,   initializeFocusTraversalKeys,   inside,   invalidate,   invalidateIfValid,   invalidateParent,   isAutoFocusTransferOnDisposal,   isBackgroundSet,   isCoalescingEnabled,   isCursorSet,   isDisplayable,   isDoubleBuffered,   isEnabled,   isEnabledImpl,   isFocusCycleRoot,   isFocusOwner,   isFocusTraversable,   isFocusTraversableOverridden,   isFocusable,   isFontSet,   isForegroundSet,   isInstanceOf,   isLightweight,   isMaximumSizeSet,   isMinimumSizeSet,   isMixingNeeded,   isNonOpaqueForMixing,   isOpaque,   isPreferredSizeSet,   isRecursivelyVisible,   isSameOrAncestorOf,   isShowing,   isValid,   isVisible,   isVisible_NoClientCode,   keyDown,   keyUp,   layout,   lightweightPaint,   lightweightPrint,   list,   list,   list,   list,   list,   locate,   location,   lostFocus,   minimumSize,   mixOnHiding,   mixOnReshaping,   mixOnShowing,   mixOnValidating,   mixOnZOrderChanging,   mouseDown,   mouseDrag,   mouseEnter,   mouseExit,   mouseMove,   mouseUp,   move,   nextFocus,   numListening,   paint,   paintAll,   paintHeavyweightComponents,   paramString,   pointRelativeToComponent,   postEvent,   postsOldMouseEvents,   preferredSize,   prepareImage,   prepareImage,   print,   printAll,   printHeavyweightComponents,   processComponentEvent,   processEvent,   processFocusEvent,   processHierarchyBoundsEvent,   processHierarchyEvent,   processInputMethodEvent,   processKeyEvent,   processMouseEvent,   processMouseMotionEvent,   processMouseWheelEvent,   relocateComponent,   remove,   removeComponentListener,   removeFocusListener,   removeHierarchyBoundsListener,   removeHierarchyListener,   removeInputMethodListener,   removeKeyListener,   removeMouseListener,   removeMouseMotionListener,   removeMouseWheelListener,   removeNotify,   removePropertyChangeListener,   removePropertyChangeListener,   repaint,   repaint,   repaint,   repaint,   requestFocus,   requestFocus,   requestFocus,   requestFocus,   requestFocusHelper,   requestFocusHelper,   requestFocusInWindow,   requestFocusInWindow,   requestFocusInWindow,   requestFocusInWindow,   reshape,   resize,   resize,   revalidate,   setAutoFocusTransferOnDisposal,   setBackground,   setBounds,   setBounds,   setBoundsOp,   setComponentOrientation,   setCursor,   setDropTarget,   setEnabled,   setFocusTraversalKeys,   setFocusTraversalKeysEnabled,   setFocusTraversalKeys_NoIDCheck,   setFocusable,   setFont,   setForeground,   setGraphicsConfiguration,   setIgnoreRepaint,   setLocale,   setLocation,   setLocation,   setMaximumSize,   setMinimumSize,   setName,   setPreferredSize,   setRequestFocusController,   setSize,   setSize,   setVisible,   show,   show,   size,   subtractAndApplyShape,   subtractAndApplyShapeBelowMe,   toString,   transferFocus,   transferFocus,   transferFocusBackward,   transferFocusBackward,   transferFocusUpCycle,   update,   updateCursorImmediately,   updateGraphicsData,   updateZOrder,   validate
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.Label Detail:
 public  void addNotify() 
    Creates the peer for this label. The peer allows us to modify the appearance of the label without changing its functionality.
 String constructComponentName() 
    Construct a name for this component. Called by getName() when the name is null.
 public AccessibleContext 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.
 public int getAlignment() 
    Gets the current alignment of this label. Possible values are Label.LEFT, Label.RIGHT, and Label.CENTER.
 public String getText() 
    Gets the text of this label.
 protected String 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.
 public synchronized  void setAlignment(int alignment) 
    Sets the alignment for this label to the specified alignment. Possible values are Label.LEFT, Label.RIGHT, and Label.CENTER.
 public  void setText(String text) 
    Sets the text for this label to the specified text.