- 所有已实现的接口:
ImageObserver,ItemSelectable,MenuContainer,Serializable,SwingConstants
- 已知子类:
JButton,JMenuItem,JToggleButton
按钮可以通过Actions 进行配置,并在某种程度上进行控制。使用带有按钮的 Action 比直接配置按钮有很多好处。有关详细信息,请参阅 摇摆组件支持Action,您可以在 如何使用动作 中找到更多信息,这是 The Java Tutorial 中的一个部分。
有关更多信息,请参阅 如何使用按钮、复选框和单选按钮,The Java Tutorial 中的一个部分。
Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder 。
- 自从:
- 1.2
-
内部类总结
内部类修饰符和类型类描述protected class此类实现了对AbstractButton类的辅助功能支持。protected class将ChangeListener扩展为可序列化。在类 javax.swing.JComponent 中声明的嵌套类/接口
JComponent.AccessibleJComponent在类 java.awt.Container 中声明的嵌套类/接口
Container.AccessibleAWTContainer -
字段摘要
字段修饰符和类型Field描述protected ActionListener按钮模型的ActionListener。static final String标识对绘制边框或不绘制边框的更改。protected ChangeEvent每个按钮实例只需要一个ChangeEvent,因为事件的唯一状态是源属性。protected ChangeListener按钮模型的changeListener。static final String标识让按钮绘制内容区域的更改。static final String标识禁用按钮时使用的图标的更改。static final String标识禁用和选择按钮时使用的图标的更改。static final String标识在聚焦或不聚焦时突出显示边框的更改。static final String标识按钮水平对齐方式的更改。static final String标识按钮水平文本位置的变化。static final String标识对表示按钮的图标的更改。protected ItemListener按钮模型的ItemListener。static final String标识按钮边距的变化。static final String标识对按钮助记符的更改。protected ButtonModel确定按钮状态的数据模型。static final String标识按钮模型中的更改。static final String标识按下按钮时使用的图标的更改。static final String标识从翻转启用到禁用或返回到启用的更改。static final String标识当光标位于按钮上时使用的图标的更改。static final String标识当光标位于按钮上并且已被选中时使用的图标的更改。static final String标识选择按钮时使用的图标的更改。static final String标识按钮文本的更改。static final String标识按钮垂直对齐方式的变化。static final String标识按钮垂直文本位置的变化。在类 javax.swing.JComponent 中声明的字段
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW在类 java.awt.Component 中声明的字段
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT在接口 java.awt.image.ImageObserver 中声明的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH在接口 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 -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述protected voidactionPropertyChanged(Action action, String propertyName) 更新按钮的状态以响应关联操作中的属性更改。void向按钮添加ActionListener。void添加一个ChangeListener到按钮。protected void将指定的组件添加到此容器的指定索引处,有关此方法的完整说明,请参阅Container.addImpl(Component, Object, int)。void添加一个ItemListener到checkbox。protected intcheckHorizontalKey(int key, String exception) 验证key参数是horizontalAlignment和horizontalTextPosition属性的合法值。protected intcheckVerticalKey(int key, String exception) 验证key参数是垂直属性的合法值。protected void设置此按钮的属性以匹配指定的Action中的属性。protected ActionListener返回添加到模型中的ActionListener。protected PropertyChangeListener创建并返回一个PropertyChangeListener负责监听来自指定Action的更改并更新相应的属性。protected ChangeListener想要以不同方式处理ChangeEvents的子类可以覆盖它以返回另一个ChangeListener实现。protected ItemListener返回添加到模型中的ItemListener。voiddoClick()以编程方式执行“点击”。voiddoClick(int pressTime) 以编程方式执行“点击”。protected voidfireActionPerformed(ActionEvent event) 通知所有已注册对此事件类型的通知感兴趣的监听。protected voidfireItemStateChanged(ItemEvent event) 通知所有已注册对此事件类型的通知感兴趣的监听。protected void通知所有已注册对此事件类型的通知感兴趣的监听。返回当前为此ActionEvent源设置的Action,如果未设置Action,则返回null。返回此按钮的操作命令。返回使用 addActionListener() 添加到此 AbstractButton 的所有ActionListener的数组。返回使用 addChangeListener() 添加到此 AbstractButton 的所有ChangeListener的数组。返回按钮禁用时使用的图标。返回按钮在禁用和选中时使用的图标。int返回作为索引的字符,外观应该为其提供装饰以表示助记字符。boolean返回hideActionText属性的值,该属性确定按钮是否显示来自Action的文本。int返回图标和文本的水平对齐方式。int返回文本相对于图标的水平位置。getIcon()返回默认图标。int返回此按钮中显示的文本和图标之间的间距量。返回使用 addItemListener() 添加到此 AbstractButton 的所有ItemListener的数组。getLabel()已弃用。返回按钮边框和标签之间的边距。int从当前模型返回键盘助记符。getModel()返回此按钮代表的模型。long获取按钮生成相应操作事件的鼠标按下事件之间所需的时间量(以毫秒为单位)。返回按钮的按下图标。返回按钮的翻转图标。返回按钮的翻转选择图标。返回按钮的选定图标。Object[]如果未选择按钮,则返回包含标签或null的数组(长度为 1)。getText()返回按钮的文本。getUI()返回呈现此组件的 L&F 对象。int返回文本和图标的垂直对齐方式。int返回文本相对于图标的垂直位置。booleanimageUpdate(Image img, int infoflags, int x, int y, int w, int h) 如果当前按钮状态的按钮图标是null或不是ImageIcon且Image等于传入的Image,则返回false;否则它将委托给超类。protected voidAbstractButton的初始化。boolean获取borderPainted属性。boolean获取contentAreaFilled属性。boolean获取paintFocus属性。boolean获取rolloverEnabled属性。boolean返回按钮的状态。protected void如果BorderPainted属性为真并且按钮有边框,则绘制按钮的边框。protected String返回此AbstractButton的字符串表示形式void从按钮中删除ActionListener。void从按钮中移除 ChangeListener。void从按钮中删除ItemListener。void通知此组件它不再有父组件。void设置Action。voidsetActionCommand(String actionCommand) 设置此按钮的动作命令。voidsetBorderPainted(boolean b) 设置borderPainted属性。voidsetContentAreaFilled(boolean b) 设置contentAreaFilled属性。voidsetDisabledIcon(Icon disabledIcon) 设置按钮的禁用图标。voidsetDisabledSelectedIcon(Icon disabledSelectedIcon) 为按钮设置禁用的选择图标。voidsetDisplayedMnemonicIndex(int index) 提供有关应修饰文本中的哪个字符以表示助记符的外观提示。voidsetEnabled(boolean b) 启用(或禁用)按钮。voidsetFocusPainted(boolean b) 设置paintFocus属性,对于要绘制的焦点状态,该属性必须为true。voidsetHideActionText(boolean hideActionText) 设置hideActionText属性,该属性确定按钮是否显示来自Action的文本。voidsetHorizontalAlignment(int alignment) 设置图标和文本的水平对齐方式。voidsetHorizontalTextPosition(int textPosition) 设置文本相对于图标的水平位置。void设置按钮的默认图标。voidsetIconTextGap(int iconTextGap) 如果同时设置了 icon 和 text 属性,则此属性定义它们之间的空间。void已弃用。- 替换为setText(text)voidsetLayout(LayoutManager mgr) 设置此容器的布局管理器,有关此方法的完整说明,请参阅Container.setLayout(LayoutManager)。void设置按钮边框和标签之间的边距空间。voidsetMnemonic(char mnemonic) 此方法现已废弃,请使用setMnemonic(int)为按钮设置助记符。voidsetMnemonic(int mnemonic) 在当前模型上设置键盘助记符。voidsetModel(ButtonModel newModel) 设置此按钮代表的模型。voidsetMultiClickThreshhold(long threshold) 设置按钮在鼠标按下事件之间生成相应操作事件所需的时间量(以毫秒为单位)。voidsetPressedIcon(Icon pressedIcon) 设置按钮的按下图标。voidsetRolloverEnabled(boolean b) 设置rolloverEnabled属性,该属性必须为true才能发生翻转效果。voidsetRolloverIcon(Icon rolloverIcon) 设置按钮的翻转图标。voidsetRolloverSelectedIcon(Icon rolloverSelectedIcon) 设置按钮的鼠标悬停选定图标。voidsetSelected(boolean b) 设置按钮的状态。voidsetSelectedIcon(Icon selectedIcon) 设置按钮的选定图标。void设置按钮的文本。void设置呈现此组件的 L&F 对象。voidsetVerticalAlignment(int alignment) 设置图标和文本的垂直对齐方式。voidsetVerticalTextPosition(int textPosition) 设置文本相对于图标的垂直位置。voidupdateUI()将 UI 属性重置为当前外观的值。在类 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, getUIClassID, 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在类 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在类 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, getAccessibleContext, 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
-
字段详细信息
-
MODEL_CHANGED_PROPERTY
标识按钮模型中的更改。- 参见:
-
TEXT_CHANGED_PROPERTY
标识按钮文本的更改。- 参见:
-
MNEMONIC_CHANGED_PROPERTY
标识对按钮助记符的更改。- 参见:
-
MARGIN_CHANGED_PROPERTY
标识按钮边距的变化。- 参见:
-
VERTICAL_ALIGNMENT_CHANGED_PROPERTY
标识按钮垂直对齐方式的变化。- 参见:
-
HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
标识按钮水平对齐方式的更改。- 参见:
-
VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
标识按钮垂直文本位置的变化。- 参见:
-
HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
标识按钮水平文本位置的变化。- 参见:
-
BORDER_PAINTED_CHANGED_PROPERTY
标识对绘制边框或不绘制边框的更改。- 参见:
-
FOCUS_PAINTED_CHANGED_PROPERTY
标识在聚焦或不聚焦时突出显示边框的更改。- 参见:
-
ROLLOVER_ENABLED_CHANGED_PROPERTY
标识从翻转启用到禁用或返回到启用的更改。- 参见:
-
CONTENT_AREA_FILLED_CHANGED_PROPERTY
标识让按钮绘制内容区域的更改。- 参见:
-
ICON_CHANGED_PROPERTY
标识对表示按钮的图标的更改。- 参见:
-
PRESSED_ICON_CHANGED_PROPERTY
标识按下按钮时使用的图标的更改。- 参见:
-
SELECTED_ICON_CHANGED_PROPERTY
标识选择按钮时使用的图标的更改。- 参见:
-
ROLLOVER_ICON_CHANGED_PROPERTY
标识当光标位于按钮上时使用的图标的更改。- 参见:
-
ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
标识当光标位于按钮上并且已被选中时使用的图标的更改。- 参见:
-
DISABLED_ICON_CHANGED_PROPERTY
标识禁用按钮时使用的图标的更改。- 参见:
-
DISABLED_SELECTED_ICON_CHANGED_PROPERTY
标识禁用和选择按钮时使用的图标的更改。- 参见:
-
model
确定按钮状态的数据模型。 -
changeListener
按钮模型的changeListener。 -
actionListener
按钮模型的ActionListener。 -
itemListener
按钮模型的ItemListener。 -
changeEvent
每个按钮实例只需要一个ChangeEvent,因为事件的唯一状态是源属性。生成的事件源始终是“this”。
-
-
构造方法详细信息
-
AbstractButton
protected AbstractButton()子类调用的构造方法。
-
-
方法详情
-
setHideActionText
@BeanProperty (expert =true, description ="Whether the text of the button should come from the <code>Action</code>.") public void setHideActionText(boolean hideActionText) 设置hideActionText属性,该属性确定按钮是否显示来自Action的文本。这仅在按钮上安装了Action时才有用。- 参数:
hideActionText-true如果按钮的text属性不应反映Action的属性;默认是false- 自从:
- 1.6
- 参见:
-
getHideActionText
public boolean getHideActionText()返回hideActionText属性的值,该属性确定按钮是否显示来自Action的文本。这仅在按钮上安装了Action时才有用。- 返回:
true如果按钮的text属性不应反映Action的属性;默认是false- 自从:
- 1.6
-
getText
返回按钮的文本。- 返回:
- 按钮文字
- 参见:
-
setText
@BeanProperty (preferred =true, visualUpdate =true, description ="The button\'s text.") public void setText(String text) 设置按钮的文本。- 参数:
text- 用于设置文本的字符串- 参见:
-
isSelected
public boolean isSelected()返回按钮的状态。如果选择了切换按钮,则为 True,否则为 false。- 返回:
- 如果切换按钮被选中,则为 true,否则为 false
-
setSelected
public void setSelected(boolean b) 设置按钮的状态。请注意,此方法不会触发actionEvent。调用doClick以执行编程操作更改。- 参数:
b- 如果按钮被选中则为真,否则为假
-
doClick
public void doClick()以编程方式执行“点击”。这与用户按下并释放按钮的效果相同。 -
doClick
public void doClick(int pressTime) 以编程方式执行“点击”。这与用户按下并释放按钮的效果相同。该按钮在视觉上保持“按下”状态pressTime毫秒。- 参数:
pressTime- “按住”按钮的时间,以毫秒为单位
-
setMargin
@BeanProperty (visualUpdate =true, description ="The space between the button\'s border and the label.") public void setMargin(Insets m) 设置按钮边框和标签之间的边距空间。设置为null将导致按钮使用默认边距。按钮的默认Border对象将使用此值来创建适当的边距。但是,如果在按钮上设置了非默认边框,则Border对象有责任创建适当的边距空间(否则该属性将被有效地忽略)。- 参数:
m- 边框和标签之间的空间
-
getMargin
返回按钮边框和标签之间的边距。- 返回:
-
一个
Insets对象,指定按钮边框和标签之间的边距 - 参见:
-
getIcon
返回默认图标。- 返回:
-
默认
Icon - 参见:
-
setIcon
@BeanProperty (visualUpdate =true, description ="The button\'s default icon") public void setIcon(Icon defaultIcon) 设置按钮的默认图标。如果没有明确设置按下图标,此图标也用作“按下”和“禁用”图标。- 参数:
defaultIcon- 用作默认图像的图标- 参见:
-
getPressedIcon
返回按钮的按下图标。- 返回:
pressedIcon属性- 参见:
-
setPressedIcon
@BeanProperty (visualUpdate =true, description ="The pressed icon for the button.") public void setPressedIcon(Icon pressedIcon) 设置按钮的按下图标。- 参数:
pressedIcon- 用作“按下”图像的图标- 参见:
-
getSelectedIcon
返回按钮的选定图标。- 返回:
selectedIcon属性- 参见:
-
setSelectedIcon
@BeanProperty (visualUpdate =true, description ="The selected icon for the button.") public void setSelectedIcon(Icon selectedIcon) 设置按钮的选定图标。- 参数:
selectedIcon- 用作“选定”图像的图标- 参见:
-
getRolloverIcon
返回按钮的翻转图标。- 返回:
rolloverIcon属性- 参见:
-
setRolloverIcon
@BeanProperty (visualUpdate =true, description ="The rollover icon for the button.") public void setRolloverIcon(Icon rolloverIcon) 设置按钮的翻转图标。- 参数:
rolloverIcon- 用作“翻转”图像的图标- 参见:
-
getRolloverSelectedIcon
返回按钮的翻转选择图标。- 返回:
rolloverSelectedIcon属性- 参见:
-
setRolloverSelectedIcon
@BeanProperty (visualUpdate =true, description ="The rollover selected icon for the button.") public void setRolloverSelectedIcon(Icon rolloverSelectedIcon) 设置按钮的鼠标悬停选定图标。- 参数:
rolloverSelectedIcon- 用作“选定翻转”图像的图标- 参见:
-
getDisabledIcon
返回按钮禁用时使用的图标。如果未设置禁用图标,这会将调用转发给外观以构建适当的禁用图标。某些外观可能不会呈现禁用的图标,在这种情况下,它们将忽略它。
- 返回:
disabledIcon属性- 参见:
-
setDisabledIcon
@BeanProperty (visualUpdate =true, description ="The disabled icon for the button.") public void setDisabledIcon(Icon disabledIcon) 设置按钮的禁用图标。- 参数:
disabledIcon- 用作禁用图像的图标- 参见:
-
getDisabledSelectedIcon
返回按钮在禁用和选中时使用的图标。如果未设置禁用的选择图标,这会将调用转发到 LookAndFeel 以从选择图标构造适当的禁用图标(如果已设置),否则将调用转发到getDisabledIcon()。一些外观可能不会呈现禁用的选定图标,在这种情况下,它们将忽略它。
- 返回:
disabledSelectedIcon属性- 参见:
-
setDisabledSelectedIcon
@BeanProperty (visualUpdate =true, description ="The disabled selection icon for the button.") public void setDisabledSelectedIcon(Icon disabledSelectedIcon) 为按钮设置禁用的选择图标。- 参数:
disabledSelectedIcon- 用作禁用选择图像的图标- 参见:
-
getVerticalAlignment
public int getVerticalAlignment()返回文本和图标的垂直对齐方式。- 返回:
verticalAlignment属性,以下值之一:SwingConstants.CENTER(默认值)SwingConstants.TOPSwingConstants.BOTTOM
-
setVerticalAlignment
@BeanProperty (visualUpdate =true, enumerationValues ={"SwingConstants.TOP","SwingConstants.CENTER","SwingConstants.BOTTOM"}, description ="The vertical alignment of the icon and text.") public void setVerticalAlignment(int alignment) 设置图标和文本的垂直对齐方式。- 参数:
alignment- 以下值之一:SwingConstants.CENTER(默认值)SwingConstants.TOPSwingConstants.BOTTOM
- 抛出:
IllegalArgumentException- 如果对齐不是上面列出的合法值之一
-
getHorizontalAlignment
public int getHorizontalAlignment()返回图标和文本的水平对齐方式。AbstractButton的默认值是SwingConstants.CENTER,但JCheckBox等子类可能使用不同的默认值。- 返回:
horizontalAlignment属性,以下值之一:SwingConstants.RIGHTSwingConstants.LEFTSwingConstants.CENTERSwingConstants.LEADINGSwingConstants.TRAILING
-
setHorizontalAlignment
@BeanProperty (visualUpdate =true, enumerationValues ={"SwingConstants.LEFT","SwingConstants.CENTER","SwingConstants.RIGHT","SwingConstants.LEADING","SwingConstants.TRAILING"}, description ="The horizontal alignment of the icon and text.") public void setHorizontalAlignment(int alignment) 设置图标和文本的水平对齐方式。AbstractButton的默认值是SwingConstants.CENTER,但JCheckBox等子类可能使用不同的默认值。- 参数:
alignment- 对齐值,以下值之一:SwingConstants.RIGHTSwingConstants.LEFTSwingConstants.CENTERSwingConstants.LEADINGSwingConstants.TRAILING
- 抛出:
IllegalArgumentException- 如果对齐不是有效值之一
-
getVerticalTextPosition
public int getVerticalTextPosition()返回文本相对于图标的垂直位置。- 返回:
verticalTextPosition属性,以下值之一:SwingConstants.CENTER(默认值)SwingConstants.TOPSwingConstants.BOTTOM
-
setVerticalTextPosition
@BeanProperty (visualUpdate =true, enumerationValues ={"SwingConstants.TOP","SwingConstants.CENTER","SwingConstants.BOTTOM"}, description ="The vertical position of the text relative to the icon.") public void setVerticalTextPosition(int textPosition) 设置文本相对于图标的垂直位置。- 参数:
textPosition- 以下值之一:SwingConstants.CENTER(默认值)SwingConstants.TOPSwingConstants.BOTTOM
-
getHorizontalTextPosition
public int getHorizontalTextPosition()返回文本相对于图标的水平位置。- 返回:
horizontalTextPosition属性,以下值之一:SwingConstants.RIGHTSwingConstants.LEFTSwingConstants.CENTERSwingConstants.LEADINGSwingConstants.TRAILING(默认值)
-
setHorizontalTextPosition
@BeanProperty (visualUpdate =true, enumerationValues ={"SwingConstants.LEFT","SwingConstants.CENTER","SwingConstants.RIGHT","SwingConstants.LEADING","SwingConstants.TRAILING"}, description ="The horizontal position of the text relative to the icon.") public void setHorizontalTextPosition(int textPosition) 设置文本相对于图标的水平位置。- 参数:
textPosition- 以下值之一:SwingConstants.RIGHTSwingConstants.LEFTSwingConstants.CENTERSwingConstants.LEADINGSwingConstants.TRAILING(默认值)
- 抛出:
IllegalArgumentException- 如果textPosition不是上面列出的合法值之一
-
getIconTextGap
public int getIconTextGap()返回此按钮中显示的文本和图标之间的间距量。- 返回:
- 一个等于文本和图标之间的像素数的 int。
- 自从:
- 1.4
- 参见:
-
setIconTextGap
@BeanProperty (visualUpdate =true, description ="If both the icon and text properties are set, this property defines the space between them.") public void setIconTextGap(int iconTextGap) 如果同时设置了 icon 和 text 属性,则此属性定义它们之间的空间。此属性的默认值为 4 像素。
这是一个 JavaBeans 绑定属性。
- 参数:
iconTextGap- 如果设置了这些属性,图标和文本之间的空间。- 自从:
- 1.4
- 参见:
-
checkHorizontalKey
验证key参数是horizontalAlignment和horizontalTextPosition属性的合法值。有效值为:SwingConstants.RIGHTSwingConstants.LEFTSwingConstants.CENTERSwingConstants.LEADINGSwingConstants.TRAILING
- 参数:
key- 要检查的属性值exception- 在为无效值抛出的IllegalArgumentException中使用的消息- 返回:
key参数- 抛出:
IllegalArgumentException- 如果键不是上面列出的合法值之一- 参见:
-
checkVerticalKey
验证key参数是垂直属性的合法值。有效值为:SwingConstants.CENTERSwingConstants.TOPSwingConstants.BOTTOM
- 参数:
key- 要检查的属性值exception- 在为无效值抛出的IllegalArgumentException中使用的消息- 返回:
key参数- 抛出:
IllegalArgumentException- 如果键不是上面列出的合法值之一
-
removeNotify
public void removeNotify()通知此组件它不再有父组件。调用此方法时,将删除在父组件链中设置的任何KeyboardAction。此方法由工具包内部调用,不应由程序直接调用。- 重写:
removeNotify在类JComponent中- 自从:
- 1.6
- 参见:
-
setActionCommand
设置此按钮的动作命令。- 参数:
actionCommand- 此按钮的动作命令
-
getActionCommand
返回此按钮的操作命令。- 返回:
- 此按钮的操作命令
-
setAction
@BeanProperty (visualUpdate =true, description ="the Action instance connected with this ActionEvent source") public void setAction(Action a) 设置Action。新的Action取代了之前设置的任何Action但不影响ActionListeners独立添加addActionListener。如果Action已经是按钮的已注册ActionListener,则不会重新注册。设置
Action会导致立即更改 摇摆组件支持Action中描述的所有属性。随后,按钮的属性会随着Action的属性更改而自动更新。此方法使用其他三种方法来设置和帮助跟踪
Action的属性值。它使用configurePropertiesFromAction方法立即更改按钮的属性。为了跟踪Action的属性值的变化,此方法注册了createActionPropertyChangeListener返回的PropertyChangeListener。当Action中的属性更改时,默认PropertyChangeListener调用actionPropertyChanged方法。- 参数:
a-AbstractButton的Action或null- 自从:
- 1.3
- 参见:
-
getAction
返回当前为此ActionEvent源设置的Action,如果未设置Action,则返回null。- 返回:
-
这个
ActionEvent来源的Action,或null - 自从:
- 1.3
- 参见:
-
configurePropertiesFromAction
设置此按钮的属性以匹配指定的Action中的属性。有关此设置的属性的更多详细信息,请参阅 摇摆组件支持Action。- 参数:
a- 从中获取属性的Action,或null- 自从:
- 1.3
- 参见:
-
actionPropertyChanged
更新按钮的状态以响应关联操作中的属性更改。从createActionPropertyChangeListener返回的PropertyChangeListener调用此方法。子类通常不需要调用它。支持额外Action属性的子类应该覆盖这个和configurePropertiesFromAction。有关此方法设置的属性列表,请参阅 摇摆组件支持
Action中的表格。- 参数:
action- 与此按钮关联的ActionpropertyName- 更改的属性的名称- 自从:
- 1.6
- 参见:
-
createActionPropertyChangeListener
创建并返回一个PropertyChangeListener负责监听来自指定Action的更改并更新相应的属性。警告:如果您将其子类化,则不要创建匿名内部类。如果你这样做,按钮的生命周期将与
Action的生命周期相关联。- 参数:
a- 按钮的动作- 返回:
PropertyChangeListener- 自从:
- 1.3
- 参见:
-
isBorderPainted
public boolean isBorderPainted()获取borderPainted属性。- 返回:
borderPainted属性的值- 参见:
-
setBorderPainted
@BeanProperty (visualUpdate =true, description ="Whether the border should be painted.") public void setBorderPainted(boolean b) 设置borderPainted属性。如果true并且按钮有边框,则绘制边框。borderPainted属性的默认值为true。一些外观可能不支持
borderPainted属性,在这种情况下他们会忽略它。- 参数:
b- 如果 true 且边框属性不是null,则绘制边框- 参见:
-
paintBorder
如果BorderPainted属性为真并且按钮有边框,则绘制按钮的边框。- 重写:
paintBorder在类JComponent中- 参数:
g- 绘制的Graphics上下文- 参见:
-
isFocusPainted
public boolean isFocusPainted()获取paintFocus属性。- 返回:
paintFocus属性- 参见:
-
setFocusPainted
@BeanProperty (visualUpdate =true, description ="Whether focus should be painted") public void setFocusPainted(boolean b) 设置paintFocus属性,对于要绘制的焦点状态,该属性必须为true。paintFocus属性的默认值为true。一些外观可能不会描绘焦点状态;他们将忽略此属性。- 参数:
b- 如果是true,应该绘制焦点状态- 参见:
-
isContentAreaFilled
public boolean isContentAreaFilled()获取contentAreaFilled属性。- 返回:
contentAreaFilled属性- 参见:
-
setContentAreaFilled
@BeanProperty (visualUpdate =true, description ="Whether the button should paint the content area or leave it transparent.") public void setContentAreaFilled(boolean b) 设置contentAreaFilled属性。如果true按钮将绘制内容区域。如果你希望有一个透明的按钮,例如一个只有图标的按钮,那么你应该将它设置为false。请勿调用给setOpaque(false)。contentAreaFilled属性的默认值为true。此功能可能会导致组件的不透明属性发生变化。
调用此函数的确切行为在逐个组件和逐个 L&F 的基础上有所不同。
- 参数:
b- 如果为真,则应填写内容;如果为 false,则内容区域未填充- 参见:
-
isRolloverEnabled
public boolean isRolloverEnabled()获取rolloverEnabled属性。- 返回:
rolloverEnabled属性的值- 参见:
-
setRolloverEnabled
@BeanProperty (visualUpdate =true, description ="Whether rollover effects should be enabled.") public void setRolloverEnabled(boolean b) 设置rolloverEnabled属性,该属性必须为true才能发生翻转效果。rolloverEnabled属性的默认值为false。某些外观可能无法实现翻转效果;他们将忽略此属性。- 参数:
b- 如果是true,应该绘制翻转效果- 参见:
-
getMnemonic
public int getMnemonic()从当前模型返回键盘助记符。- 返回:
- 来自模型的键盘助记符
-
setMnemonic
@BeanProperty (visualUpdate =true, description ="the keyboard character mnemonic") public void setMnemonic(int mnemonic) 在当前模型上设置键盘助记符。助记键是与外观的无鼠标修饰符(通常是 Alt)结合使用的键,如果焦点包含在该按钮的祖先窗口中的某处,则将激活该按钮。助记符必须对应于键盘上的单个键,并且应使用
java.awt.event.KeyEvent中定义的VK_XXX键码之一指定。这些代码和更广泛的国际键盘代码可以通过java.awt.event.KeyEvent.getExtendedKeyCodeForChar获得。助记符不区分大小写,因此具有相应键码的键事件将导致按钮被激活,无论是否按下 Shift 修饰符。如果助记符定义的字符在按钮的标签字符串中找到,第一次出现的字符将被加下划线以向用户指示助记符。
- 参数:
mnemonic- 代表助记符的键码- 参见:
-
setMnemonic
@BeanProperty (visualUpdate =true, description ="the keyboard character mnemonic") public void setMnemonic(char mnemonic) 此方法现已废弃,请使用setMnemonic(int)为按钮设置助记符。此方法仅设计用于处理介于“a”和“z”或“A”和“Z”之间的字符值。- 参数:
mnemonic- 指定助记值的字符- 参见:
-
setDisplayedMnemonicIndex
@BeanProperty (visualUpdate =true, description ="the index into the String to draw the keyboard character mnemonic at") public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException 提供有关应修饰文本中的哪个字符以表示助记符的外观提示。并非所有外观都支持这一点。值为-1 表示没有助记词,字符串中不包含助记符字符,或者开发人员不希望显示助记词。this 的值随着与助记符相关的属性(例如助记符本身、文本...)的变化而更新。如果您不希望为默认字符加下划线,则只应调用此方法。例如,如果文本为“另存为”,助记符为“a”,而您希望修饰“A”,如“保存”As',您必须在调用
setMnemonic(KeyEvent.VK_A)之后调用setDisplayedMnemonicIndex(5)。- 参数:
index- 要下划线的字符串索引- 抛出:
IllegalArgumentException- 如果index>= 文本长度,或者 < -1,将被抛出- 自从:
- 1.4
- 参见:
-
getDisplayedMnemonicIndex
public int getDisplayedMnemonicIndex()返回作为索引的字符,外观应该为其提供装饰以表示助记字符。- 返回:
- 代表助记符的索引
- 自从:
- 1.4
- 参见:
-
setMultiClickThreshhold
public void setMultiClickThreshhold(long threshold) 设置按钮在鼠标按下事件之间生成相应操作事件所需的时间量(以毫秒为单位)。在初始鼠标按下发生(并生成动作事件)之后,任何间隔小于阈值的后续鼠标按下事件都将被忽略,并且不会生成相应的动作事件。默认情况下,阈值为 0,这意味着每次按下鼠标,都会触发一个动作事件,无论鼠标点击的速度有多快。在不希望出现这种行为的按钮中(例如,对话框中的“确定”按钮),应将此阈值设置为适当的正值。- 参数:
threshold- 鼠标按下事件之间生成相应动作事件所需的时间量- 抛出:
IllegalArgumentException- 如果阈值 < 0- 自从:
- 1.4
- 参见:
-
getMultiClickThreshhold
public long getMultiClickThreshhold()获取按钮生成相应操作事件的鼠标按下事件之间所需的时间量(以毫秒为单位)。- 返回:
- 鼠标按下事件之间生成相应动作事件所需的时间量
- 自从:
- 1.4
- 参见:
-
getModel
返回此按钮代表的模型。- 返回:
model属性- 参见:
-
setModel
@BeanProperty (description ="Model that the Button uses.") public void setModel(ButtonModel newModel) 设置此按钮代表的模型。- 参数:
newModel- 新的ButtonModel- 参见:
-
getUI
返回呈现此组件的 L&F 对象。- 重写:
getUI在类JComponent中- 返回:
- ButtonUI 对象
- 参见:
-
setUI
@BeanProperty (hidden =true, visualUpdate =true, description ="The UI object that implements the LookAndFeel.") public void setUI(ButtonUI ui) 设置呈现此组件的 L&F 对象。- 参数:
ui-ButtonUIL&F 对象- 参见:
-
updateUI
public void updateUI()将 UI 属性重置为当前外观的值。AbstractButton的子类型应该覆盖它以更新 UI。例如,JButton可能会执行以下操作:setUI((ButtonUI)UIManager.getUI( "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));- 重写:
updateUI在类JComponent中- 参见:
-
addImpl
将指定的组件添加到此容器的指定索引处,有关此方法的完整说明,请参阅Container.addImpl(Component, Object, int)。- 重写:
addImpl在类Container中- 参数:
comp- 要添加的组件constraints- 表示此组件布局约束的对象index- 在容器列表中插入组件的位置,其中-1表示追加到末尾- 抛出:
IllegalArgumentException- 如果index无效IllegalArgumentException- 如果将容器的父级添加到自身IllegalArgumentException- 如果向容器添加窗口- 自从:
- 1.5
- 参见:
-
setLayout
设置此容器的布局管理器,有关此方法的完整说明,请参阅Container.setLayout(LayoutManager)。 -
addChangeListener
添加一个ChangeListener到按钮。- 参数:
l- 要添加的监听器
-
removeChangeListener
从按钮中移除 ChangeListener。- 参数:
l- 要删除的监听器
-
getChangeListeners
返回使用 addChangeListener() 添加到此 AbstractButton 的所有ChangeListener的数组。- 返回:
-
添加所有
ChangeListener或如果未添加任何监听器,则为空数组 - 自从:
- 1.4
-
fireStateChanged
protected void fireStateChanged()通知所有已注册对此事件类型的通知感兴趣的监听。事件实例是延迟创建的。- 参见:
-
addActionListener
向按钮添加ActionListener。- 参数:
l- 要添加的ActionListener
-
removeActionListener
从按钮中删除ActionListener。如果监听器是当前为按钮设置的Action,则Action设置为null。- 参数:
l- 要删除的监听器
-
getActionListeners
返回使用 addActionListener() 添加到此 AbstractButton 的所有ActionListener的数组。- 返回:
-
添加所有
ActionListener或如果未添加任何监听器,则为空数组 - 自从:
- 1.4
-
createChangeListener
想要以不同方式处理ChangeEvents的子类可以覆盖它以返回另一个ChangeListener实现。- 返回:
-
新的
ChangeListener
-
fireActionPerformed
通知所有已注册对此事件类型的通知感兴趣的监听器。事件实例是使用event参数延迟创建的。- 参数:
event-ActionEvent对象- 参见:
-
fireItemStateChanged
通知所有已注册对此事件类型的通知感兴趣的监听器。事件实例是使用event参数延迟创建的。- 参数:
event-ItemEvent对象- 参见:
-
createActionListener
返回添加到模型中的ActionListener。- 返回:
ActionListener
-
createItemListener
返回添加到模型中的ItemListener。- 返回:
ItemListener
-
setEnabled
public void setEnabled(boolean b) 启用(或禁用)按钮。- 重写:
setEnabled在类JComponent中- 参数:
b- true 启用按钮,否则为 false- 参见:
-
getLabel
已弃用。- 替换为getText返回标签文本。- 返回:
-
包含标签的
String
-
setLabel
@Deprecated @BeanProperty (description ="Replace by setText(text)") public void setLabel(String label) 已弃用。- 替换为setText(text)设置标签文本。- 参数:
label- 包含文本的String
-
addItemListener
添加一个ItemListener到checkbox。- 指定者:
addItemListener在接口ItemSelectable中- 参数:
l- 要添加的ItemListener- 参见:
-
removeItemListener
从按钮中删除ItemListener。- 指定者:
removeItemListener在接口ItemSelectable中- 参数:
l- 要删除的ItemListener- 参见:
-
getItemListeners
返回使用 addItemListener() 添加到此 AbstractButton 的所有ItemListener的数组。- 返回:
-
添加所有
ItemListener或如果未添加任何监听器,则为空数组 - 自从:
- 1.4
-
getSelectedObjects
如果未选择按钮,则返回包含标签或null的数组(长度为 1)。- 指定者:
getSelectedObjects在接口ItemSelectable中- 返回:
-
包含 1 个对象的数组:按钮的文本,如果该项目被选中;否则
null
-
init
AbstractButton的初始化。- 参数:
text- 按钮的文字icon- 显示在按钮上的图标图像
-
imageUpdate
如果当前按钮状态的按钮图标是null或不是ImageIcon且Image等于传入的Image,则返回false;否则它将委托给超类。- 指定者:
imageUpdate在接口ImageObserver中- 重写:
imageUpdate在类Component中- 参数:
img- 要比较的Imageinfoflags- 用于在更新图像时重新绘制按钮的标志,它决定了要绘制多少x- x 坐标y- y 坐标w- 宽度h- 高度- 返回:
false如果信息标志表明图像已完全加载;true否则。- 参见:
-
paramString
返回此AbstractButton的字符串表示形式。此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。返回的字符串可能为空,但可能不是null。覆盖
paramString以提供有关 JFC 组件的特定新方面的信息。- 重写:
paramString在类JComponent中- 返回:
-
这个
AbstractButton的字符串表示
-
getText