java.lang.Object
java.awt.Component
java.awt.Label
- 所有已实现的接口:
-
ImageObserver
,MenuContainer
,Serializable
,Accessible
Label
对象是用于在容器中放置文本的组件。标签显示单行只读文本。应用程序可以更改文本,但用户不能直接编辑它。
例如,以下代码 . . .
setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); add(new Label("Hi There!")); add(new Label("Another Label"));
会产生以下标签:
- 自版本:
- 1.0
- 另请参阅:
-
Nested Class Summary
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
表示标签应该居中显示。static final int
表示标签应该左对齐。static final int
表示标签应该右对齐。Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
为此标签创建对等体。获取与此标签关联的AccessibleContext。int
获取此标签的当前对齐方式。getText()
获取此标签的文本。protected String
返回表示此Label
状态的字符串。void
setAlignment
(int alignment) 将此标签的对齐方式设置为指定的对齐方式。void
将此标签的文本设置为指定的文本。Methods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, 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, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, 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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
Field Details
-
LEFT
public static final int LEFT表示标签应该左对齐。- 另请参阅:
-
CENTER
public static final int CENTER表示标签应该居中显示。- 另请参阅:
-
RIGHT
public static final int RIGHT表示标签应该右对齐。- 另请参阅:
-
-
Constructor Details
-
Label
构造一个空标签。标签的文本为空字符串""
。- 抛出:
-
HeadlessException
- 如果GraphicsEnvironment.isHeadless()返回true。 - 另请参阅:
-
Label
使用指定的文本字符串构造一个新的左对齐标签。- 参数:
-
text
- 标签显示的字符串。接受null
值而不会引发NullPointerException。 - 抛出:
-
HeadlessException
- 如果GraphicsEnvironment.isHeadless()返回true。 - 另请参阅:
-
Label
使用指定的文本字符串和指定的对齐方式构造一个新的标签。对alignment
的可能值为Label.LEFT
、Label.RIGHT
和Label.CENTER
。- 参数:
-
text
- 标签显示的字符串。接受null
值而不会引发NullPointerException。 -
alignment
- 对齐值。 - 抛出:
-
HeadlessException
- 如果GraphicsEnvironment.isHeadless()返回true。 - 另请参阅:
-
-
Method Details
-
addNotify
public void addNotify()为此标签创建对等体。对等体允许我们修改标签的外观而不改变其功能。 -
getAlignment
public int getAlignment()获取此标签的当前对齐方式。可能的值为Label.LEFT
、Label.RIGHT
和Label.CENTER
。- 返回:
- 此标签的对齐方式
- 另请参阅:
-
setAlignment
public void setAlignment(int alignment) 将此标签的对齐方式设置为指定的对齐方式。可能的值为Label.LEFT
、Label.RIGHT
和Label.CENTER
。- 参数:
-
alignment
- 要设置的对齐方式。 - 抛出:
-
IllegalArgumentException
- 如果给定的alignment
值不正确。 - 另请参阅:
-
getText
获取此标签的文本。- 返回:
-
此标签的文本,如果文本已设置为
null
,则返回null
。 - 另请参阅:
-
setText
将此标签的文本设置为指定的文本。- 参数:
-
text
- 此标签显示的文本。如果text
为null
,则会被视为空字符串""
。 - 另请参阅:
-
paramString
返回表示此Label
状态的字符串。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null
。- 覆盖:
-
paramString
在类Component
- 返回:
- 此标签的参数字符串
-
getAccessibleContext
获取与此标签关联的AccessibleContext。对于标签,AccessibleContext采用AccessibleAWTLabel的形式。如有必要,将创建一个新的AccessibleAWTLabel实例。- 指定者:
-
getAccessibleContext
在接口Accessible
- 覆盖:
-
getAccessibleContext
在类Component
- 返回:
- 作为此标签的AccessibleContext的AccessibleAWTLabel
- 自版本:
- 1.3
-