public class JButton extends AbstractButton implements Accessible
按钮可以配置,并在一定程度上受到Action的控制。 使用带按钮的Action除了直接配置按钮之外,还有很多好处。
请参阅Swing Components Supporting Action了解更多详情,您可以找到更多信息How to Use Actions ,在Java教程的部分。
见How to Use Buttons, Check Boxes, and Radio Buttons在Java教程的信息和使用按钮的例子。
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。
从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
| Modifier and Type | Class and Description |
|---|---|
protected class |
JButton.AccessibleJButton
这个类实现了可访问性支持
JButton类。
|
AbstractButton.AccessibleAbstractButton,
AbstractButton.ButtonChangeListenerJComponent.AccessibleJComponentContainer.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyactionListener,
BORDER_PAINTED_CHANGED_PROPERTY,
changeEvent, changeListener,
CONTENT_AREA_FILLED_CHANGED_PROPERTY,
DISABLED_ICON_CHANGED_PROPERTY,
DISABLED_SELECTED_ICON_CHANGED_PROPERTY,
FOCUS_PAINTED_CHANGED_PROPERTY,
HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY,
ICON_CHANGED_PROPERTY,
itemListener, MARGIN_CHANGED_PROPERTY,
MNEMONIC_CHANGED_PROPERTY,
model, MODEL_CHANGED_PROPERTY,
PRESSED_ICON_CHANGED_PROPERTY,
ROLLOVER_ENABLED_CHANGED_PROPERTY,
ROLLOVER_ICON_CHANGED_PROPERTY,
ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY,
SELECTED_ICON_CHANGED_PROPERTY,
TEXT_CHANGED_PROPERTY,
VERTICAL_ALIGNMENT_CHANGED_PROPERTY,
VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
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_ALIGNMENTBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WESTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JButton()
创建一个没有设置文本或图标的按钮。
|
JButton(Action a)
创建一个按钮,其中的属性取自提供的
Action 。
|
JButton(Icon icon)
创建一个带有图标的按钮。
|
JButton(String text)
创建一个带文本的按钮。
|
JButton(String text,
Icon icon)
创建一个带有初始文本和图标的按钮。
|
| Modifier and Type | Method and Description |
|---|---|
AccessibleContext
|
getAccessibleContext()
获取
AccessibleContext与此相关
JButton 。
|
String |
getUIClassID()
返回一个字符串,它指定呈现此组件的L&F类的名称。
|
boolean |
isDefaultButton()
获取
defaultButton属性的值,如果
true意味着此按钮是其
JRootPane的当前默认按钮。
|
boolean |
isDefaultCapable()
获取
defaultCapable属性的值。
|
protected String
|
paramString()
返回此
JButton的字符串表示
JButton 。
|
void |
removeNotify()
覆盖
JComponent.removeNotify ,以检查此按钮当前被设置为在默认按钮
RootPane ,如果是的话,设置
RootPane的默认按钮
null ,以确保
RootPane不继续停留在无效的按钮引用。
|
void |
setDefaultCapable(boolean defaultCapable)
设置
defaultCapable属性,它确定此按钮是否可以成为其根窗格的默认按钮。
|
void |
updateUI()
将UI属性重置为当前外观的值。
|
actionPropertyChanged,
addActionListener,
addChangeListener,
addImpl,
addItemListener,
checkHorizontalKey,
checkVerticalKey,
configurePropertiesFromAction,
createActionListener,
createActionPropertyChangeListener,
createChangeListener,
createItemListener,
doClick, doClick, fireActionPerformed,
fireItemStateChanged,
fireStateChanged,
getAction, getActionCommand,
getActionListeners,
getChangeListeners,
getDisabledIcon,
getDisabledSelectedIcon,
getDisplayedMnemonicIndex,
getHideActionText,
getHorizontalAlignment,
getHorizontalTextPosition,
getIcon, getIconTextGap,
getItemListeners,
getLabel, getMargin, getMnemonic,
getModel, getMultiClickThreshhold,
getPressedIcon,
getRolloverIcon,
getRolloverSelectedIcon,
getSelectedIcon,
getSelectedObjects,
getText, getUI, getVerticalAlignment,
getVerticalTextPosition,
imageUpdate,
init,
isBorderPainted,
isContentAreaFilled,
isFocusPainted,
isRolloverEnabled,
isSelected, paintBorder,
removeActionListener,
removeChangeListener,
removeItemListener,
setAction,
setActionCommand,
setBorderPainted,
setContentAreaFilled,
setDisabledIcon,
setDisabledSelectedIcon,
setDisplayedMnemonicIndex,
setEnabled,
setFocusPainted,
setHideActionText,
setHorizontalAlignment,
setHorizontalTextPosition,
setIcon,
setIconTextGap,
setLabel,
setLayout,
setMargin,
setMnemonic,
setMnemonic, setModel,
setMultiClickThreshhold,
setPressedIcon,
setRolloverEnabled,
setRolloverIcon,
setRolloverSelectedIcon,
setSelected,
setSelectedIcon,
setText,
setUI,
setVerticalAlignment,
setVerticalTextPosition
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,
paintChildren,
paintComponent,
paintImmediately,
paintImmediately,
print, printAll,
printBorder,
printChildren,
printComponent,
processComponentKeyEvent,
processKeyBinding,
processKeyEvent,
processMouseEvent,
processMouseMotionEvent,
putClientProperty,
registerKeyboardAction,
registerKeyboardAction,
removeAncestorListener,
removeVetoableChangeListener,
repaint,
repaint,
requestDefaultFocus,
requestFocus, requestFocus,
requestFocusInWindow,
requestFocusInWindow,
resetKeyboardActions,
reshape, revalidate, scrollRectToVisible,
setActionMap,
setAlignmentX,
setAlignmentY,
setAutoscrolls,
setBackground,
setBorder,
setComponentPopupMenu,
setDebugGraphicsOptions,
setDefaultLocale,
setDoubleBuffered,
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,
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,
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
public JButton()
public JButton(Icon icon)
icon - 按钮上显示的图标图标
@ConstructorProperties(value="text") public JButton(String text)
text - 按钮的文字
public JButton(Action a)
Action 。
a -
Action用于指定新的按钮
public void updateUI()
updateUI在
AbstractButton
JComponent.updateUI()
public String getUIClassID()
getUIClassID在
JComponent
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public boolean isDefaultButton()
defaultButton属性的值,如果true意味着此按钮是其JRootPane的当前默认按钮。
大多数外观和感觉呈现默认按钮不同,并可能提供绑定来访问默认按钮。
defaultButton属性
JRootPane.setDefaultButton(javax.swing.JButton)
,
isDefaultCapable()
public boolean isDefaultCapable()
defaultCapable属性的值。
defaultCapable属性
setDefaultCapable(boolean)
,
isDefaultButton()
,
JRootPane.setDefaultButton(javax.swing.JButton)
public void setDefaultCapable(boolean defaultCapable)
defaultCapable属性,该属性确定此按钮是否可以成为其根窗格的默认按钮。
defaultCapable属性的默认值为true ,除非外观和外观另有规定。
defaultCapable - true如果此按钮将能够作为RootPane上的默认按钮;
否则false
isDefaultCapable()
public void removeNotify()
JComponent.removeNotify ,以检查此按钮当前被设置为在默认按钮
RootPane ,如果是的话,设置
RootPane的默认按钮
null ,以确保
RootPane不继续停留在无效的按钮引用。
protected String paramString()
JButton的字符串表示JButton 。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null 。
paramString在
AbstractButton
JButton的字符串表示
JButton
public AccessibleContext getAccessibleContext()
AccessibleContext与此相关JButton 。
为JButton s时, AccessibleContext需要一个的形式AccessibleJButton 。
如果需要,将创建一个新的AccessibleJButton实例。
getAccessibleContext在界面
Accessible
getAccessibleContext在
Component
AccessibleJButton ,作为这个
AccessibleContext的
JButton