Module java.desktop
Package javax.swing

Class AbstractButton

所有已实现的接口:
ImageObserver, ItemSelectable, MenuContainer, Serializable, SwingConstants
直接已知的子类:
JButton, JMenuItem, JToggleButton

@JavaBean(defaultProperty="UI") public abstract class AbstractButton extends JComponent implements ItemSelectable, SwingConstants
定义了按钮和菜单项的通用行为。

按钮可以通过Action进行配置,并在一定程度上受其控制。使用Action与按钮具有许多优点,超出了直接配置按钮的范围。有关更多详细信息,请参阅支持Action的Swing组件,您可以在如何使用Actions中找到更多信息,这是《Java教程》中的一节。

更多信息请参见如何使用按钮、复选框和单选按钮,这是《Java教程》中的一节。

警告: 该类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans包中。请参阅XMLEncoder

自JDK版本:
1.2
  • Field Details

    • MODEL_CHANGED_PROPERTY

      public static final String MODEL_CHANGED_PROPERTY
      标识按钮模型的更改。
      参见:
    • TEXT_CHANGED_PROPERTY

      public static final String TEXT_CHANGED_PROPERTY
      标识按钮文本的更改。
      参见:
    • MNEMONIC_CHANGED_PROPERTY

      public static final String MNEMONIC_CHANGED_PROPERTY
      标识按钮边距的更改。
      参见:
    • MARGIN_CHANGED_PROPERTY

      public static final String MARGIN_CHANGED_PROPERTY
      标识按钮垂直对齐方式的更改。
      参见:
    • VERTICAL_ALIGNMENT_CHANGED_PROPERTY

      public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY
      标识按钮水平对齐方式的更改。
      参见:
    • HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY

      public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
      标识按钮垂直文本位置的更改。
      参见:
    • VERTICAL_TEXT_POSITION_CHANGED_PROPERTY

      public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
      标识按钮水平文本位置的更改。
      参见:
    • HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY

      public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
      标识是否绘制边框的更改。
      参见:
    • BORDER_PAINTED_CHANGED_PROPERTY

      public static final String BORDER_PAINTED_CHANGED_PROPERTY
      标识是否在焦点时突出显示边框的更改。
      参见:
    • FOCUS_PAINTED_CHANGED_PROPERTY

      public static final String FOCUS_PAINTED_CHANGED_PROPERTY
      标识启用或禁用悬停效果的更改。
      参见:
    • ROLLOVER_ENABLED_CHANGED_PROPERTY

      public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY
      标识从启用到禁用悬停效果的更改,或者从禁用到启用的更改。
      参见:
    • CONTENT_AREA_FILLED_CHANGED_PROPERTY

      public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY
      标识按钮是否绘制内容区域的更改。
      参见:
    • ICON_CHANGED_PROPERTY

      public static final String ICON_CHANGED_PROPERTY
      标识代表按钮的图标的更改。
      参见:
    • PRESSED_ICON_CHANGED_PROPERTY

      public static final String PRESSED_ICON_CHANGED_PROPERTY
      标识按钮被按下时使用的图标的更改。
      参见:
    • SELECTED_ICON_CHANGED_PROPERTY

      public static final String SELECTED_ICON_CHANGED_PROPERTY
      标识按钮被选中时使用的图标的更改。
      参见:
    • ROLLOVER_ICON_CHANGED_PROPERTY

      public static final String ROLLOVER_ICON_CHANGED_PROPERTY
      标识鼠标悬停在按钮上时使用的图标的更改。
      参见:
    • ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY

      public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
      标识鼠标悬停在按钮上并且按钮已被选中时使用的图标的更改。
      参见:
    • DISABLED_ICON_CHANGED_PROPERTY

      public static final String DISABLED_ICON_CHANGED_PROPERTY
      标识按钮被禁用时使用的图标的更改。
      参见:
    • DISABLED_SELECTED_ICON_CHANGED_PROPERTY

      public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY
      标识按钮被禁用并且已被选中时使用的图标的更改。
      参见:
    • model

      protected ButtonModel model
      确定按钮状态的数据模型。
    • changeListener

      protected ChangeListener changeListener
      按钮模型的changeListener
    • actionListener

      protected ActionListener actionListener
      按钮模型的ActionListener
    • itemListener

      protected ItemListener itemListener
      按钮模型的ItemListener
    • changeEvent

      protected transient ChangeEvent changeEvent
      每个按钮实例只需要一个ChangeEvent,因为事件的唯一状态是源属性。生成的事件源始终为"this"。
  • Constructor Details

    • AbstractButton

      protected AbstractButton()
      子类调用的构造函数。
  • Method Details

    • 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 - 如果按钮的text属性不应反映Action的属性,则为true;默认为false
      自:
      1.6
      参见:
    • getHideActionText

      public boolean getHideActionText()
      返回hideActionText属性的值,确定按钮是否显示来自Action的文本。仅当按钮上安装了Action时才有用。
      返回:
      如果按钮的text属性不应反映Action的属性,则为true;默认为false
      自:
      1.6
    • getText

      public String 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 - 如果按钮被选中,则为true,否则为false
    • doClick

      public void doClick()
      程序化执行"点击"操作。这与用户按下并释放按钮的操作相同。
    • doClick

      public void doClick(int pressTime)
      Programmatically perform a "click". This does the same thing as if the user had pressed and released the button. The button stays visually "pressed" for pressTime milliseconds.
      Parameters:
      pressTime - the time to "hold down" the button, in milliseconds
    • setMargin

      @BeanProperty(visualUpdate=true, description="The space between the button\'s border and the label.") public void setMargin(Insets m)
      Sets space for margin between the button's border and the label. Setting to null will cause the button to use the default margin. The button's default Border object will use this value to create the proper margin. However, if a non-default border is set on the button, it is that Border object's responsibility to create the appropriate margin space (else this property will effectively be ignored).
      Parameters:
      m - the space between the border and the label
    • getMargin

      public Insets getMargin()
      Returns the margin between the button's border and the label.
      Returns:
      an Insets object specifying the margin between the botton's border and the label
      See Also:
    • getIcon

      public Icon getIcon()
      Returns the default icon.
      Returns:
      the default Icon
      See Also:
    • setIcon

      @BeanProperty(visualUpdate=true, description="The button\'s default icon") public void setIcon(Icon defaultIcon)
      Sets the button's default icon. This icon is also used as the "pressed" and "disabled" icon if there is no explicitly set pressed icon.
      Parameters:
      defaultIcon - the icon used as the default image
      See Also:
    • getPressedIcon

      public Icon getPressedIcon()
      Returns the pressed icon for the button.
      Returns:
      the pressedIcon property
      See Also:
    • setPressedIcon

      @BeanProperty(visualUpdate=true, description="The pressed icon for the button.") public void setPressedIcon(Icon pressedIcon)
      Sets the pressed icon for the button.
      Parameters:
      pressedIcon - the icon used as the "pressed" image
      See Also:
    • getSelectedIcon

      public Icon getSelectedIcon()
      Returns the selected icon for the button.
      Returns:
      the selectedIcon property
      See Also:
    • setSelectedIcon

      @BeanProperty(visualUpdate=true, description="The selected icon for the button.") public void setSelectedIcon(Icon selectedIcon)
      Sets the selected icon for the button.
      Parameters:
      selectedIcon - the icon used as the "selected" image
      See Also:
    • getRolloverIcon

      public Icon getRolloverIcon()
      Returns the rollover icon for the button.
      Returns:
      the rolloverIcon property
      See Also:
    • setRolloverIcon

      @BeanProperty(visualUpdate=true, description="The rollover icon for the button.") public void setRolloverIcon(Icon rolloverIcon)
      Sets the rollover icon for the button.
      Parameters:
      rolloverIcon - the icon used as the "rollover" image
      See Also:
    • getRolloverSelectedIcon

      public Icon getRolloverSelectedIcon()
      Returns the rollover selection icon for the button.
      Returns:
      the rolloverSelectedIcon property
      See Also:
    • setRolloverSelectedIcon

      @BeanProperty(visualUpdate=true, description="The rollover selected icon for the button.") public void setRolloverSelectedIcon(Icon rolloverSelectedIcon)
      Sets the rollover selected icon for the button.
      Parameters:
      rolloverSelectedIcon - the icon used as the "selected rollover" image
      See Also:
    • getDisabledIcon

      public Icon getDisabledIcon()
      Returns the icon used by the button when it's disabled. If no disabled icon has been set this will forward the call to the look and feel to construct an appropriate disabled Icon.

      Some look and feels might not render the disabled Icon, in which case they will ignore this.

      Returns:
      the disabledIcon property
      See Also:
    • setDisabledIcon

      @BeanProperty(visualUpdate=true, description="The disabled icon for the button.") public void setDisabledIcon(Icon disabledIcon)
      Sets the disabled icon for the button.
      Parameters:
      disabledIcon - the icon used as the disabled image
      See Also:
    • getDisabledSelectedIcon

      public Icon getDisabledSelectedIcon()
      Returns the icon used by the button when it's disabled and selected. If no disabled selection icon has been set, this will forward the call to the LookAndFeel to construct an appropriate disabled Icon from the selection icon if it has been set and to getDisabledIcon() otherwise.

      Some look and feels might not render the disabled selected Icon, in which case they will ignore this.

      Returns:
      the disabledSelectedIcon property
      See Also:
    • setDisabledSelectedIcon

      @BeanProperty(visualUpdate=true, description="The disabled selection icon for the button.") public void setDisabledSelectedIcon(Icon disabledSelectedIcon)
      Sets the disabled selection icon for the button.
      Parameters:
      disabledSelectedIcon - the icon used as the disabled selection image
      See Also:
    • getVerticalAlignment

      public int getVerticalAlignment()
      Returns the vertical alignment of the text and icon.
      Returns:
      the verticalAlignment property, one of the following values:
      • SwingConstants.CENTER (the default)
      • SwingConstants.TOP
      • SwingConstants.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)
      Sets the vertical alignment of the icon and text.
      Parameters:
      alignment - one of the following values:
      • SwingConstants.CENTER (the default)
      • SwingConstants.TOP
      • SwingConstants.BOTTOM
      Throws:
      IllegalArgumentException - if the alignment is not one of the legal values listed above
    • getHorizontalAlignment

      public int getHorizontalAlignment()
      Returns the horizontal alignment of the icon and text. AbstractButton's default is SwingConstants.CENTER, but subclasses such as JCheckBox may use a different default.
      Returns:
      the horizontalAlignment property, one of the following values:
      • SwingConstants.RIGHT
      • SwingConstants.LEFT
      • SwingConstants.CENTER
      • SwingConstants.LEADING
      • SwingConstants.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)
      Sets the horizontal alignment of the icon and text. AbstractButton's default is SwingConstants.CENTER, but subclasses such as JCheckBox may use a different default.
      Parameters:
      alignment - the alignment value, one of the following values:
      • SwingConstants.RIGHT
      • SwingConstants.LEFT
      • SwingConstants.CENTER
      • SwingConstants.LEADING
      • SwingConstants.TRAILING
      Throws:
      IllegalArgumentException - if the alignment is not one of the valid values
    • getVerticalTextPosition

      public int getVerticalTextPosition()
      Returns the vertical position of the text relative to the icon.
      Returns:
      the verticalTextPosition property, one of the following values:
      • SwingConstants.CENTER (the default)
      • SwingConstants.TOP
      • SwingConstants.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)
      Sets the vertical position of the text relative to the icon.
      Parameters:
      textPosition - one of the following values:
      • SwingConstants.CENTER (the default)
      • SwingConstants.TOP
      • SwingConstants.BOTTOM
    • getHorizontalTextPosition

      public int getHorizontalTextPosition()
      Returns the horizontal position of the text relative to the icon.
      Returns:
      the horizontalTextPosition property, one of the following values:
      • SwingConstants.RIGHT
      • SwingConstants.LEFT
      • SwingConstants.CENTER
      • SwingConstants.LEADING
      • SwingConstants.TRAILING (the default)
    • 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)
      Sets the horizontal position of the text relative to the icon.
      参数:
      textPosition - 以下值之一:
      • SwingConstants.RIGHT
      • SwingConstants.LEFT
      • SwingConstants.CENTER
      • SwingConstants.LEADING
      • SwingConstants.TRAILING(默认值)
      抛出:
      IllegalArgumentException - 如果textPosition不是上述合法值之一
    • getIconTextGap

      public int getIconTextGap()
      返回此按钮中显示的文本和图标之间的空间量。
      返回:
      一个整数,表示文本和图标之间的像素数。
      自版本:
      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)
      如果同时设置了图标和文本属性,则此属性定义它们之间的间距。

      此属性的默认值为4像素。

      这是一个JavaBeans绑定属性。

      参数:
      iconTextGap - 如果设置了这些属性,则图标和文本之间的间距。
      自版本:
      1.4
      另请参阅:
    • checkHorizontalKey

      protected int checkHorizontalKey(int key, String exception)
      验证key参数是否是horizontalAlignmenthorizontalTextPosition属性的合法值。有效值为:
      • SwingConstants.RIGHT
      • SwingConstants.LEFT
      • SwingConstants.CENTER
      • SwingConstants.LEADING
      • SwingConstants.TRAILING
      参数:
      key - 要检查的属性值
      exception - 在IllegalArgumentException中使用的消息,用于表示无效值
      返回:
      key参数
      抛出:
      IllegalArgumentException - 如果key不是上述合法值之一
      另请参阅:
    • checkVerticalKey

      protected int checkVerticalKey(int key, String exception)
      验证key参数是否是垂直属性的合法值。有效值为:
      • SwingConstants.CENTER
      • SwingConstants.TOP
      • SwingConstants.BOTTOM
      参数:
      key - 要检查的属性值
      exception - 在IllegalArgumentException中使用的消息,用于表示无效值
      返回:
      key参数
      抛出:
      IllegalArgumentException - 如果key不是上述合法值之一
    • removeNotify

      public void removeNotify()
      通知此组件它不再有父组件。调用此方法时,将删除在父组件链中设置的任何KeyboardAction。此方法由工具包内部调用,不应直接由程序调用。
      覆盖:
      removeNotify 在类 JComponent
      自版本:
      1.6
      另请参阅:
    • setActionCommand

      public void setActionCommand(String actionCommand)
      设置此按钮的操作命令。
      参数:
      actionCommand - 此按钮的操作命令
    • getActionCommand

      public String getActionCommand()
      返回此按钮的操作命令。
      返回:
      此按钮的操作命令
    • setAction

      @BeanProperty(visualUpdate=true, description="the Action instance connected with this ActionEvent source") public void setAction(Action a)
      设置Action。新的Action替换先前设置的任何Action,但不影响独立添加的ActionListeners。如果Action已经是按钮的注册ActionListener,则不会重新注册。

      设置Action会立即更改所有在支持Action的Swing组件中描述的属性。随后,随着Action的属性更改,按钮的属性会自动更新。

      此方法使用其他三个方法来设置和帮助跟踪Action的属性值。它使用configurePropertiesFromAction方法立即更改按钮的属性。为了跟踪Action的属性值的更改,此方法注册createActionPropertyChangeListener返回的PropertyChangeListener。默认的PropertyChangeListenerAction的属性更改时调用actionPropertyChanged方法。

      参数:
      a - AbstractButtonAction,或null
      自版本:
      1.3
      另请参阅:
    • getAction

      public Action getAction()
      返回当前设置的Action,用于此ActionEvent源,如果未设置Action,则返回null
      返回:
      ActionEvent源的Action,或null
      自版本:
      1.3
      另请参阅:
    • configurePropertiesFromAction

      protected void configurePropertiesFromAction(Action a)
      设置此按钮的属性以匹配指定Action中的属性。有关设置的属性,请参阅支持Action的Swing组件以获取更多详细信息。
      参数:
      a - 从中获取属性的Action,或null
      自版本:
      1.3
      另请参阅:
    • actionPropertyChanged

      protected void actionPropertyChanged(Action action, String propertyName)
      根据关联操作中的属性更改更新按钮的状态。此方法从createActionPropertyChangeListener返回的PropertyChangeListener中调用。通常不需要子类调用此方法。支持其他Action属性的子类应该重写此方法和configurePropertiesFromAction

      请参阅支持Action的Swing组件中的表格,了解此方法设置的属性列表。

      参数:
      action - 与此按钮关联的Action
      propertyName - 更改的属性的名称
      自版本:
      1.6
      另请参阅:
    • createActionPropertyChangeListener

      protected PropertyChangeListener createActionPropertyChangeListener(Action a)
      创建并返回一个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

      protected void paintBorder(Graphics g)
      如果BorderPainted属性为true且按钮有边框,则绘制按钮的边框。
      覆盖:
      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

      此函数可能会导致组件的不透明属性发生变化。

      调用此函数的确切行为因组件和外观感觉而异。

      参数:
      b - 如果为true,则应填充内容;如果为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表示没有助记键,助记键字符不包含在字符串中,或开发人员不希望显示助记键。

      此值在与助记键相关的属性更改(例如助记键本身、文本等)时会更新。只有在不希望默认字符被下划线时才需要调用此方法。例如,如果文本为'Save As',助记键为'a',并且您希望将'A'装饰为'Save 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

      public ButtonModel getModel()
      返回此按钮表示的模型。
      返回:
      model属性
      参见:
    • setModel

      @BeanProperty(description="Model that the Button uses.") public void setModel(ButtonModel newModel)
      设置此按钮表示的模型。
      参数:
      newModel - 新的ButtonModel
      参见:
    • getUI

      public ButtonUI getUI()
      返回呈现此组件的外观对象。
      覆盖:
      getUI 在类 JComponent
      返回:
      ButtonUI对象
      参见:
    • setUI

      @BeanProperty(hidden=true, visualUpdate=true, description="The UI object that implements the LookAndFeel.") public void setUI(ButtonUI ui)
      设置呈现此组件的外观对象。
      参数:
      ui - ButtonUI外观对象
      参见:
    • updateUI

      public void updateUI()
      将UI属性重置为当前外观的值。AbstractButton的子类型应该覆盖此方法以更新UI。例如,JButton可能会执行以下操作:
            setUI((ButtonUI)UIManager.getUI(
                "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));
       
      覆盖:
      updateUI 在类 JComponent
      参见:
    • addImpl

      protected void addImpl(Component comp, Object constraints, int index)
      将指定的组件添加到此容器的指定索引处,请参阅Container.addImpl(Component, Object, int)以获取此方法的完整描述。
      覆盖:
      addImpl 在类 Container
      参数:
      comp - 要添加的组件
      constraints - 表达此组件的布局约束的对象
      index - 要插入组件的容器列表中的位置,其中-1表示追加到末尾
      抛出:
      IllegalArgumentException - 如果index无效
      IllegalArgumentException - 如果将容器的父级添加到自身
      IllegalArgumentException - 如果将窗口添加到容器
      自:
      1.5
      参见:
    • setLayout

      public void setLayout(LayoutManager mgr)
      为此容器设置布局管理器,请参阅Container.setLayout(LayoutManager)以获取此方法的完整描述。
      覆盖:
      setLayout 在类 Container
      参数:
      mgr - 指定的布局管理器
      自:
      1.5
      参见:
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      向按钮添加一个ChangeListener
      参数:
      l - 要添加的监听器
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      从按钮中删除一个ChangeListener
      参数:
      l - 要删除的监听器
    • getChangeListeners

      @BeanProperty(bound=false) public ChangeListener[] getChangeListeners()
      返回通过addChangeListener()添加到此AbstractButton的所有ChangeListener的数组。
      返回:
      所有已添加的ChangeListener或空数组(如果未添加任何监听器)
      自:
      1.4
    • fireStateChanged

      protected void fireStateChanged()
      通知所有已注册对此事件类型感兴趣的监听器。事件实例是延迟创建的。
      参见:
    • addActionListener

      public void addActionListener(ActionListener l)
      向按钮添加一个ActionListener
      参数:
      l - 要添加的ActionListener
    • removeActionListener

      public void removeActionListener(ActionListener l)
      从按钮中删除一个ActionListener。如果监听器是按钮当前设置的Action,则Action将设置为null
      参数:
      l - 要删除的监听器
    • getActionListeners

      @BeanProperty(bound=false) public ActionListener[] getActionListeners()
      返回通过addActionListener()添加到此AbstractButton的所有ActionListener的数组。
      返回:
      所有已添加的ActionListener或空数组(如果未添加任何监听器)
      自:
      1.4
    • createChangeListener

      protected ChangeListener createChangeListener()
      想要以不同方式处理ChangeEvents的子类可以重写此方法以返回另一个ChangeListener实现。
      返回:
      新的ChangeListener
    • fireActionPerformed

      protected void fireActionPerformed(ActionEvent event)
      通知所有已注册对此事件类型感兴趣的监听器。事件实例是使用event参数延迟创建的。
      参数:
      event - ActionEvent对象
      参见:
    • fireItemStateChanged

      protected void fireItemStateChanged(ItemEvent event)
      通知所有已注册对此事件类型感兴趣的监听器。事件实例是使用event参数延迟创建的。
      参数:
      event - ItemEvent对象
      参见:
    • createActionListener

      protected ActionListener createActionListener()
      返回添加到模型的ActionListener
      返回:
      ActionListener
    • createItemListener

      protected ItemListener createItemListener()
      返回添加到模型的ItemListener
      返回:
      ItemListener
    • setEnabled

      public void setEnabled(boolean b)
      启用(或禁用)按钮。
      覆盖:
      setEnabled 在类 JComponent
      参数:
      b - 为true时启用按钮,否则为false
      参见:
    • getLabel

      @Deprecated public String getLabel()
      Deprecated.
      - Replaced by getText
      返回标签文本。
      返回:
      包含标签的String
    • setLabel

      @Deprecated @BeanProperty(description="Replace by setText(text)") public void setLabel(String label)
      Deprecated.
      - Replaced by setText(text)
      设置标签文本。
      参数:
      label - 包含文本的String
    • addItemListener

      public void addItemListener(ItemListener l)
      checkbox添加一个ItemListener
      指定者:
      addItemListener 在接口 ItemSelectable
      参数:
      l - 要添加的ItemListener
      参见:
    • removeItemListener

      public void removeItemListener(ItemListener l)
      从按钮中删除一个ItemListener
      指定者:
      removeItemListener 在接口 ItemSelectable
      参数:
      l - 要删除的ItemListener
      参见:
    • getItemListeners

      @BeanProperty(bound=false) public ItemListener[] getItemListeners()
      返回通过addItemListener()添加到此AbstractButton的所有ItemListener的数组。
      返回:
      所有已添加的ItemListener或空数组(如果未添加任何监听器)
      自:
      1.4
    • getSelectedObjects

      @BeanProperty(bound=false) public Object[] getSelectedObjects()
      返回包含标签的数组(长度为1),如果按钮未选定,则返回null
      指定者:
      getSelectedObjects 在接口 ItemSelectable
      返回:
      包含1个对象的数组:如果项目已选定,则为按钮的文本;否则为null
    • init

      protected void init(String text, Icon icon)
      AbstractButton的初始化。
      参数:
      text - 按钮的文本
      icon - 要显示在按钮上的图标图像
    • imageUpdate

      public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
      如果当前按钮状态的按钮图标为null或不是具有等于传入ImageImageIcon,则返回false;否则将委托给超类。
      指定由:
      imageUpdate 在接口 ImageObserver
      覆盖:
      imageUpdate 在类 Component
      参数:
      img - 要比较的Image
      infoflags - 用于在图像更新时重绘按钮的标志,确定要绘制多少内容
      x - x坐标
      y - y坐标
      w - 宽度
      h - 高度
      返回:
      如果infoflags指示图像已完全加载,则返回false; 否则返回true.
      参见:
    • paramString

      protected String paramString()
      返回此AbstractButton的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null

      重写paramString以提供有关JFC组件特定新方面的信息。

      覆盖:
      paramString 在类 JComponent
      返回:
      AbstractButton的字符串表示形式