public class JLabel extends JComponent implements SwingConstants, Accessible
一个JLabel
对象可以显示文本,图像,或两者。您可以指定标签的显示区域中的位置,标签的内容是通过设置垂直和水平对齐方式对齐的。默认情况下,标签垂直居中显示在它们的显示区域中。文本只有标签是领先的边缘对齐,默认情况下,图像只标签是水平为中心,默认情况下。
您还可以指定文本相对于图像的位置。默认情况下,文本是在图像的后缘上,与文本和图像垂直对齐。
标签的前缘和后缘是从其ComponentOrientation
财产价值的确定。目前,默认设置Mapcomponentorientation前缘和后缘至右左。
最后,你可以使用setIconTextGap
方法指定像素多少应该文本和图像之间出现。默认为4像素。
看到进一步的文件在java教程How to Use Labels。
警告: Swing是线程不安全的。更多信息见Swing's Threading Policy。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans
包。请看XMLEncoder
。
Modifier and Type | Class and Description |
---|---|
protected class |
JLabel.AccessibleJLabel
用于获取此对象的可访问角色的类。
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected Component |
labelFor |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JLabel()
创建一个没有图像
JLabel 实例和标题为空字符串。
|
JLabel(Icon image)
创建一个具有指定的图像
JLabel 实例。
|
JLabel(Icon image, int horizontalAlignment)
创建一个
JLabel 实例与指定的图像和水平对齐。
|
JLabel(String text)
创建一个具有指定文本
JLabel 实例。
|
JLabel(String text, Icon icon, int horizontalAlignment)
创建一个具有指定文本、图像
JLabel 实例,水平对齐方式。
|
JLabel(String text, int horizontalAlignment)
创建一个
JLabel 实例与指定的文本水平对齐方式。
|
Modifier and Type | Method and Description |
---|---|
protected int |
checkHorizontalKey(int key, String message)
验证的关键是对线形设计性质的法律价值。
|
protected int |
checkVerticalKey(int key, String message)
验证密钥对、纵断面线形或verticaltextposition性质的法律价值。
|
AccessibleContext |
getAccessibleContext()
获得此对象的accessiblecontext
|
Icon |
getDisabledIcon()
返回标签被禁用时使用的图标。
|
int |
getDisplayedMnemonic()
返回的键码,表明记忆的关键。
|
int |
getDisplayedMnemonicIndex()
返回字符,作为指标,外观和感觉应该提供装饰为代表的助记符。
|
int |
getHorizontalAlignment()
返回沿X轴的标签内容的对齐方式。
|
int |
getHorizontalTextPosition()
返回标签文本的水平位置,相对于它的图像。
|
Icon |
getIcon()
返回标签显示的图形图像(标志符号)。
|
int |
getIconTextGap()
返回在该标签中显示的文本和图标之间的空间量。
|
Component |
getLabelFor()
获取该组件,这是标签。
|
String |
getText()
返回标签显示的文本字符串。
|
LabelUI |
getUI()
返回呈现此组件的L和F对象。
|
String |
getUIClassID()
返回一个字符串,指定呈现此组件的“L”和“F”类的名称。
|
int |
getVerticalAlignment()
返回沿Y轴上标签内容的对齐方式。
|
int |
getVerticalTextPosition()
返回标签文本的垂直位置,相对于它的图像。
|
boolean |
imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
这是,如果当前图标的图像不等于通过在图像
img 返回false。
|
protected String |
paramString()
该方法返回的字符串表示形式。
|
void |
setDisabledIcon(Icon disabledIcon)
设置图标显示,如果这个方法是“残疾人”(JLabel。setenabled(假))。
|
void |
setDisplayedMnemonic(char aChar)
指定displayedmnemonic为char值。
|
void |
setDisplayedMnemonic(int key)
指定一个密码,表明记忆的关键。
|
void |
setDisplayedMnemonicIndex(int index)
提供了一个暗示的外观和感觉对文本的字符应该装饰代表记忆。
|
void |
setHorizontalAlignment(int alignment)
设置沿X轴上的标签内容的对齐方式。
|
void |
setHorizontalTextPosition(int textPosition)
设置标签的文本的水平位置,相对于它的图像。
|
void |
setIcon(Icon icon)
定义此组件将显示的图标。
|
void |
setIconTextGap(int iconTextGap)
如果设置了图标和文本属性,则此属性定义了它们之间的空间。
|
void |
setLabelFor(Component c)
设置这是标签的组件。
|
void |
setText(String text)
定义此组件将显示的单行文本。
|
void |
setUI(LabelUI ui)
设置呈现此组件的“L”和F对象。
|
void |
setVerticalAlignment(int alignment)
设置沿Y轴上的标签内容的对齐方式。
|
void |
setVerticalTextPosition(int textPosition)
设置标签文本的垂直位置,相对于它的图像。
|
void |
updateUI()
重置UI属性从目前看价值和感觉。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected Component labelFor
public JLabel(String text, Icon icon, int horizontalAlignment)
JLabel
实例,水平对齐方式。标签在其显示区域中垂直居中。文本在图像的后缘上。
text
-被标签显示的文本。
icon
的图像被显示的标签。
horizontalAlignment
-下列常数定义在
SwingConstants
:
LEFT
,
CENTER
,
RIGHT
,
LEADING
或
TRAILING
。
public JLabel(String text, int horizontalAlignment)
JLabel
实例与指定的文本水平对齐方式。标签在其显示区域中垂直居中。
text
-被标签显示的文本。
horizontalAlignment
-下列常数定义在
SwingConstants
:
LEFT
,
CENTER
,
RIGHT
,
LEADING
或
TRAILING
。
public JLabel(String text)
JLabel
实例。标签对准其显示区域的前缘,并垂直居中。
text
-被标签显示的文本。
public JLabel(Icon image, int horizontalAlignment)
JLabel
实例与指定的图像和水平对齐。标签在其显示区域中垂直居中。
image
的图像被显示的标签。
horizontalAlignment
-下列常数定义在
SwingConstants
:
LEFT
,
CENTER
,
RIGHT
,
LEADING
或
TRAILING
。
public JLabel(Icon image)
JLabel
实例。标签以垂直和水平在显示区域为中心。
image
的图像被显示的标签。
public JLabel()
JLabel
实例和标题为空字符串。标签在其显示区域中垂直居中。标签的内容,一旦设置,将显示在标签的显示区域的领先优势。
public LabelUI getUI()
public void setUI(LabelUI ui)
ui
- labelui L和F的对象
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
updateUI
方法重写,继承类
JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID
方法重写,继承类
JComponent
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public String getText()
setText(java.lang.String)
public void setText(String text)
此属性的默认值为空。
这是一个JavaBeans属性绑定。
public Icon getIcon()
setIcon(javax.swing.Icon)
public void setIcon(Icon icon)
此属性的默认值为空。
这是一个JavaBeans属性绑定。
public Icon getDisabledIcon()
一些外观和感觉可能不会渲染禁用图标,在这种情况下,他们会忽略这个。
disabledIcon
财产
setDisabledIcon(javax.swing.Icon)
,
LookAndFeel.getDisabledIcon(javax.swing.JComponent, javax.swing.Icon)
,
ImageIcon
public void setDisabledIcon(Icon disabledIcon)
此属性的默认值为空。
disabledIcon
的图标显示在组件被禁用
getDisabledIcon()
,
JComponent.setEnabled(boolean)
public void setDisplayedMnemonic(int key)
public void setDisplayedMnemonic(char aChar)
aChar
-一个字符指定要显示的记忆
setDisplayedMnemonic(int)
public int getDisplayedMnemonic()
getLabelFor()
,
setLabelFor(java.awt.Component)
public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException
这个值是有关记忆的性能变化,更新(如记忆本身,文字…)。如果你不希望默认字符被下划线,你应该只需要调用这个。例如,如果文本是“另存为”,在“A”的记忆,和你想要的'加以装饰,为节省一s ',你必须调用后调用setDisplayedMnemonic(KeyEvent.VK_A)
setDisplayedMnemonicIndex(5)
。
index
指数为字符串下划线
IllegalArgumentException
将抛出如果
index
> =长度的文本,或<1
public int getDisplayedMnemonicIndex()
setDisplayedMnemonicIndex(int)
protected int checkHorizontalKey(int key, String message)
key
-属性值检查
message
时的详细信息
IllegalArgumentException
如果关键不是左,右,中心,前导或尾随。
setHorizontalTextPosition(int)
,
setHorizontalAlignment(int)
protected int checkVerticalKey(int key, String message)
key
-属性值检查
message
时的详细信息
IllegalArgumentException
如果钥匙不顶,中心或底部。
setVerticalAlignment(int)
,
setVerticalTextPosition(int)
public int getIconTextGap()
setIconTextGap(int)
public void setIconTextGap(int iconTextGap)
此属性的默认值为4像素。
这是一个JavaBeans属性绑定。
getIconTextGap()
public int getVerticalAlignment()
SwingConstants
:
TOP
,
CENTER
,或
BOTTOM
。
SwingConstants
,
setVerticalAlignment(int)
public void setVerticalAlignment(int alignment)
此属性的默认值为中心。
alignment
-下列常数定义在
SwingConstants
:
TOP
,
CENTER
(默认值),或
BOTTOM
。
SwingConstants
,
getVerticalAlignment()
public int getHorizontalAlignment()
SwingConstants
:
LEFT
,
CENTER
,
RIGHT
,
LEADING
或
TRAILING
。
setHorizontalAlignment(int)
,
SwingConstants
public void setHorizontalAlignment(int alignment)
这是一个JavaBeans属性绑定。
alignment
-下列常数定义在
SwingConstants
:
LEFT
,
CENTER
(图像只有标签默认),
RIGHT
,
LEADING
(只有文字的标签默认)或
TRAILING
。
SwingConstants
,
getHorizontalAlignment()
public int getVerticalTextPosition()
SwingConstants
:
TOP
,
CENTER
,或
BOTTOM
。
setVerticalTextPosition(int)
,
SwingConstants
public void setVerticalTextPosition(int textPosition)
此属性的默认值为中心。
这是一个JavaBeans属性绑定。
textPosition
-下列常数定义在
SwingConstants
:
TOP
,
CENTER
(默认值),或
BOTTOM
。
SwingConstants
,
getVerticalTextPosition()
public int getHorizontalTextPosition()
SwingConstants
:
LEFT
,
CENTER
,
RIGHT
,
LEADING
或
TRAILING
。
SwingConstants
public void setHorizontalTextPosition(int textPosition)
textPosition
-下列常数定义在
SwingConstants
:
LEFT
,
CENTER
,
RIGHT
,
LEADING
,或
TRAILING
(默认)。
IllegalArgumentException
SwingConstants
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
img
返回false。
imageUpdate
接口
ImageObserver
imageUpdate
方法重写,继承类
Component
img
-图像观察
infoflags
看
imageUpdate
更多信息
x
的X坐标
y
的Y坐标
w
-宽度
h
-高度
false
如果infoflags表明图像完全加载;
true
否则。
ImageObserver
,
Component.imageUpdate(java.awt.Image, int, int, int, int, int)
protected String paramString()
null
。
paramString
方法重写,继承类
JComponent
public Component getLabelFor()
getDisplayedMnemonic()
,
setDisplayedMnemonic(int)
public void setLabelFor(Component c)
c
这个标签的组件,或null如果标签是不是一个成分标签
getDisplayedMnemonic()
,
setDisplayedMnemonic(int)
public AccessibleContext getAccessibleContext()
getAccessibleContext
接口
Accessible
getAccessibleContext
方法重写,继承类
Component
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.