java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JButton
- 所有已实现的接口:
-
ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,Accessible
,SwingConstants
- 直接已知的子类:
-
BasicArrowButton
,MetalComboBoxButton
@JavaBean(defaultProperty="UIClassID", description="An implementation of a \"push\" button.") public class JButton extends AbstractButton implements Accessible
"push"按钮的实现。
按钮可以通过Action
进行配置和控制。使用Action
与按钮有许多好处,超出了直接配置按钮的范围。有关更多详细信息,请参阅支持Action
的Swing组件,您可以在如何使用Actions中找到更多信息,这是The Java Tutorial中的一节。
请参阅The Java Tutorial中的如何使用按钮、复选框和单选按钮以获取有关使用按钮的信息和示例。
警告: Swing不是线程安全的。有关更多信息,请参阅Swing的线程策略。
警告: 该类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans
包中。请参阅XMLEncoder
。
- 自1.2版本起:
- 1.2
-
Nested Class Summary
Nested classes/interfaces declared in class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields declared in class javax.swing.AbstractButton
actionListener, 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
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
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
Fields declared in interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription获取与此JButton
关联的AccessibleContext
。返回一个字符串,指定呈现此组件的L&F类的名称。boolean
获取defaultButton
属性的值,如果为true
,则表示此按钮是其JRootPane
的当前默认按钮。boolean
获取defaultCapable
属性的值。protected String
返回此JButton
的字符串表示形式。void
重写JComponent.removeNotify
以检查此按钮当前是否设置为RootPane
上的默认按钮,如果是,则将RootPane
的默认按钮设置为null
,以确保RootPane
不保留无效的按钮引用。void
setDefaultCapable
(boolean defaultCapable) 设置defaultCapable
属性,该属性确定此按钮是否可以成为其根窗格的默认按钮。void
updateUI()
重置UI属性为当前外观的值。Methods declared in class javax.swing.AbstractButton
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
Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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
Methods declared in class java.awt.Container
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
Methods declared in class java.awt.Component
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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JButton
public JButton()创建一个没有设置文本或图标的按钮。 -
JButton
创建一个带有图标的按钮。- 参数:
-
icon
- 要显示在按钮上的图标图像
-
JButton
创建一个带有文本的按钮。- 参数:
-
text
- 按钮的文本
-
JButton
创建一个从提供的Action
中获取属性的按钮。- 参数:
-
a
- 用于指定新按钮的Action
- 自1.3版本起:
- 1.3
-
JButton
创建一个带有初始文本和图标的按钮。- 参数:
-
text
- 按钮的文本 -
icon
- 要显示在按钮上的图标图像
-
-
Method Details
-
updateUI
public void updateUI()重置UI属性为当前外观的值。- 重写:
-
updateUI
在类AbstractButton
中 - 另请参阅:
-
getUIClassID
@BeanProperty(bound=false, expert=true, description="A string that specifies the name of the L&F class.") public String getUIClassID()返回一个字符串,指定呈现此组件的L&F类的名称。- 重写:
-
getUIClassID
在类JComponent
中 - 返回:
- 字符串"ButtonUI"
- 另请参阅:
-
isDefaultButton
@BeanProperty(bound=false, description="Whether or not this button is the default button") public boolean isDefaultButton()获取defaultButton
属性的值,如果为true
,则表示此按钮是其JRootPane
的当前默认按钮。大多数外观和感觉都以不同的方式呈现默认按钮,并且可能提供绑定以访问默认按钮。- 返回:
-
defaultButton
属性的值 - 另请参阅:
-
isDefaultCapable
public boolean isDefaultCapable()获取defaultCapable
属性的值。- 返回:
-
defaultCapable
属性的值 - 另请参阅:
-
setDefaultCapable
@BeanProperty(visualUpdate=true, description="Whether or not this button can be the default button") public void setDefaultCapable(boolean defaultCapable) 设置defaultCapable
属性,该属性确定此按钮是否可以成为其根窗格的默认按钮。除非外观和感觉另有规定,默认情况下defaultCapable
属性的值为true
。- 参数:
-
defaultCapable
- 如果此按钮将能够成为RootPane
上的默认按钮,则为true
;否则为false
- 另请参阅:
-
removeNotify
public void removeNotify()重写JComponent.removeNotify
以检查此按钮当前是否设置为RootPane
上的默认按钮,如果是,则将RootPane
的默认按钮设置为null
,以确保RootPane
不保留无效的按钮引用。- 重写:
-
removeNotify
在类AbstractButton
中 - 另请参阅:
-
paramString
返回此JButton
的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不会为null
。- 重写:
-
paramString
在类AbstractButton
中 - 返回:
-
此
JButton
的字符串表示形式
-
getAccessibleContext
@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this Button.") public AccessibleContext getAccessibleContext()获取与此JButton
关联的AccessibleContext
。对于JButton
,AccessibleContext
采用AccessibleJButton
的形式。如有必要,将创建一个新的AccessibleJButton
实例。- 指定者:
-
getAccessibleContext
在接口Accessible
中 - 重写:
-
getAccessibleContext
在类Component
中 - 返回:
-
作为此
JButton
的AccessibleContext
的AccessibleJButton
-