|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
public abstract class AbstractButton
定义按钮和菜单项的一般行为。
按钮可以进行配置,以及通过 Action 进行某种程度的控制。使用带有按钮的 Action 具有除直接配置按钮之外的许多优点。有关更多信息,请参阅支持 Action 的 Swing 组件,在 The Java Tutorial 中的 How
to Use Actions 一节中可以找到更多信息。
有关更多信息,请参阅 The Java Tutorial 中的 How to Use Buttons, Check Boxes, and Radio Buttons 一节。
警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
| 嵌套类摘要 | |
|---|---|
protected class |
AbstractButton.AccessibleAbstractButton
此类实现对 AbstractButton 类的可访问性支持。 |
protected class |
AbstractButton.ButtonChangeListener
将 ChangeListener 扩展为可序列化的。 |
| 从类 javax.swing.JComponent 继承的嵌套类/接口 |
|---|
JComponent.AccessibleJComponent |
| 从类 java.awt.Container 继承的嵌套类/接口 |
|---|
Container.AccessibleAWTContainer |
| 从类 java.awt.Component 继承的嵌套类/接口 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 从类 javax.swing.JComponent 继承的字段 |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| 从类 java.awt.Component 继承的字段 |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| 从接口 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 |
| 从接口 java.awt.image.ImageObserver 继承的字段 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 构造方法摘要 | |
|---|---|
AbstractButton()
|
|
| 方法摘要 | |
|---|---|
protected void |
actionPropertyChanged(Action action,
String propertyName)
更新按钮的状态以响应相关的操作中的属性更改。 |
void |
addActionListener(ActionListener l)
将一个 ActionListener 添加到按钮中。 |
void |
addChangeListener(ChangeListener l)
向按钮添加一个 ChangeListener。 |
protected void |
addImpl(Component comp,
Object constraints,
int index)
将指定组件添加到此容器的指定索引所在的位置上,有关此方法的完整描述,请参阅 Container.addImpl(Component, Object, int)。 |
void |
addItemListener(ItemListener l)
将一个 ItemListener 添加到 checkbox 中。 |
protected int |
checkHorizontalKey(int key,
String exception)
验证 key 参数是否为 horizontalAlignment 和 horizontalTextPosition 属性的合法值。 |
protected int |
checkVerticalKey(int key,
String exception)
验证 key 参数是否为垂直属性的合法值。 |
protected void |
configurePropertiesFromAction(Action a)
在此按钮上设置属性以匹配指定 Action 中的属性。 |
protected ActionListener |
createActionListener()
|
protected PropertyChangeListener |
createActionPropertyChangeListener(Action a)
创建并返回 PropertyChangeListener,它负责侦听指定 Action 的更改以及更新适当的属性。 |
protected ChangeListener |
createChangeListener()
想以不同的方式处理 ChangeEvent 的子类可以重写此方法,以返回另一个 ChangeListener 实现。 |
protected ItemListener |
createItemListener()
|
void |
doClick()
以编程方式执行“单击”。 |
void |
doClick(int pressTime)
以编程方式执行“单击”。 |
protected void |
fireActionPerformed(ActionEvent event)
通知所有需要此事件类型的通知的已注册侦听器。 |
protected void |
fireItemStateChanged(ItemEvent event)
通知所有需要此事件类型的通知的已注册侦听器。 |
protected void |
fireStateChanged()
通知所有需要此事件类型的通知的已注册侦听器。 |
Action |
getAction()
返回当前为此 ActionEvent 源设置的 Action,如果没有设置任何 Action,则返回 null。 |
String |
getActionCommand()
返回此按钮的动作命令。 |
ActionListener[] |
getActionListeners()
返回使用 addActionListener() 添加到此 AbstractButton 的所有 ActionListener 组成的数组。 |
ChangeListener[] |
getChangeListeners()
返回使用 addChangeListener() 添加到此 AbstractButton 中的所有 ChangeListener 组成的数组。 |
Icon |
getDisabledIcon()
返回禁用按钮时按钮使用的图标。 |
Icon |
getDisabledSelectedIcon()
返回禁用并选择按钮时按钮使用的图标。 |
int |
getDisplayedMnemonicIndex()
以索引形式返回字符,它表示助记符字符,外观应该对其提供装饰。 |
boolean |
getHideActionText()
返回 hideActionText 属性的值,该属性确定按钮是否显示 Action 的文本。 |
int |
getHorizontalAlignment()
返回图标和文本的水平对齐方式。 |
int |
getHorizontalTextPosition()
返回文本相对于图标的水平位置。 |
Icon |
getIcon()
返回默认图标。 |
int |
getIconTextGap()
返回此按钮中显示的文本与图标之间的间隔量。 |
ItemListener[] |
getItemListeners()
返回使用 addItemListener() 添加到此 AbstractButton 中的所有 ItemListener 组成的数组。 |
String |
getLabel()
已过时。 - 由 getText 取代 |
Insets |
getMargin()
返回按钮边框和标签之间的空白。 |
int |
getMnemonic()
返回当前模型中的键盘助记符。 |
ButtonModel |
getModel()
返回此按钮表示的模型。 |
long |
getMultiClickThreshhold()
获取对按钮按下鼠标到生成相应动作事件所需的时间量(以毫秒为单位)。 |
Icon |
getPressedIcon()
返回按钮的按下图标。 |
Icon |
getRolloverIcon()
返回按钮的翻转图标。 |
Icon |
getRolloverSelectedIcon()
返回按钮的翻转选定图标。 |
Icon |
getSelectedIcon()
返回按钮的选择图标。 |
Object[] |
getSelectedObjects()
返回包含标签的数组(长度为 1),如果没有选择按钮,则返回 null。 |
String |
getText()
返回按钮的文本。 |
ButtonUI |
getUI()
返回呈现此组件的 L&F 对象。 |
int |
getVerticalAlignment()
返回文本和图标的垂直对齐方式。 |
int |
getVerticalTextPosition()
返回文本相对于图标的垂直位置。 |
boolean |
imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h)
重写的此方法在当前 Icon 的 Image 不等于传入的 Image img 时返回 false。 |
protected void |
init(String text,
Icon icon)
|
boolean |
isBorderPainted()
获取 borderPainted 属性。 |
boolean |
isContentAreaFilled()
获取 contentAreaFilled 属性。 |
boolean |
isFocusPainted()
获取 paintFocus 属性。 |
boolean |
isRolloverEnabled()
获取 rolloverEnabled 属性。 |
boolean |
isSelected()
返回按钮的状态。 |
protected void |
paintBorder(Graphics g)
如果 BorderPainted 属性为 true 并且按钮有边框,则绘制该按钮边框。 |
protected String |
paramString()
返回此 AbstractButton 的字符串表示形式。 |
void |
removeActionListener(ActionListener l)
从按钮中移除一个 ActionListener。 |
void |
removeChangeListener(ChangeListener l)
从按钮中移除一个 ChangeListener。 |
void |
removeItemListener(ItemListener l)
从按钮中移除一个 ItemListener。 |
void |
removeNotify()
通知此组件它不再有父组件。 |
void |
setAction(Action a)
设置 Action。 |
void |
setActionCommand(String actionCommand)
设置此按钮的动作命令。 |
void |
setBorderPainted(boolean b)
设置 borderPainted 属性。 |
void |
setContentAreaFilled(boolean b)
设置 contentAreaFilled 属性。 |
void |
setDisabledIcon(Icon disabledIcon)
设置按钮的禁用图标。 |
void |
setDisabledSelectedIcon(Icon disabledSelectedIcon)
设置按钮的禁用选择图标。 |
void |
setDisplayedMnemonicIndex(int index)
提供关于应该装饰文本中哪一个字符来表示助记符的外观提示。 |
void |
setEnabled(boolean b)
启用(或禁用)按钮。 |
void |
setFocusPainted(boolean b)
设置 paintFocus 属性,对于要绘制的焦点状态,该属性必须为 true。 |
void |
setHideActionText(boolean hideActionText)
设置 hideActionText 属性,该属性确定按钮是否显示 Action 的文本。 |
void |
setHorizontalAlignment(int alignment)
设置图标和文本的水平对齐方式。 |
void |
setHorizontalTextPosition(int textPosition)
设置文本相对于图标的水平位置。 |
void |
setIcon(Icon defaultIcon)
设置按钮的默认图标。 |
void |
setIconTextGap(int iconTextGap)
如果图标和文本的属性都已设置,则此属性定义图标和文本之间的间隔。 |
void |
setLabel(String label)
已过时。 - 由 setText(text) 取代 |
void |
setLayout(LayoutManager mgr)
为此容器设置布局管理器,有关此方法的完整描述,请参阅 Container.setLayout(LayoutManager)。 |
void |
setMargin(Insets m)
设置按钮边框和标签之间的空白。 |
void |
setMnemonic(char mnemonic)
此方法现在已废弃,请使用 setMnemonic(int) 来设置按钮的助记符。 |
void |
setMnemonic(int mnemonic)
设置当前模型上的键盘助记符。 |
void |
setModel(ButtonModel newModel)
设置此按钮表示的模型。 |
void |
setMultiClickThreshhold(long threshhold)
设置对按钮按下鼠标到生成相应动作事件所需的时间量(以毫秒为单位)。 |
void |
setPressedIcon(Icon pressedIcon)
设置按钮的按下图标。 |
void |
setRolloverEnabled(boolean b)
设置 rolloverEnabled 属性,若需要翻转效果,该属性必须为 true。 |
void |
setRolloverIcon(Icon rolloverIcon)
设置按钮的翻转图标。 |
void |
setRolloverSelectedIcon(Icon rolloverSelectedIcon)
设置按钮的翻转选择图标。 |
void |
setSelected(boolean b)
设置按钮的状态。 |
void |
setSelectedIcon(Icon selectedIcon)
设置按钮的选择图标。 |
void |
setText(String text)
设置按钮的文本。 |
void |
setUI(ButtonUI ui)
设置呈现此组件的 L&F 对象。 |
void |
setVerticalAlignment(int alignment)
设置图标和文本的垂直对齐方式。 |
void |
setVerticalTextPosition(int textPosition)
设置文本相对于图标的垂直位置。 |
void |
updateUI()
将 UI 属性重置为当前外观中的一个值。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 字段详细信息 |
|---|
public static final String MODEL_CHANGED_PROPERTY
public static final String TEXT_CHANGED_PROPERTY
public static final String MNEMONIC_CHANGED_PROPERTY
public static final String MARGIN_CHANGED_PROPERTY
public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY
public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
public static final String BORDER_PAINTED_CHANGED_PROPERTY
public static final String FOCUS_PAINTED_CHANGED_PROPERTY
public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY
public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY
public static final String ICON_CHANGED_PROPERTY
public static final String PRESSED_ICON_CHANGED_PROPERTY
public static final String SELECTED_ICON_CHANGED_PROPERTY
public static final String ROLLOVER_ICON_CHANGED_PROPERTY
public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
public static final String DISABLED_ICON_CHANGED_PROPERTY
public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY
protected ButtonModel model
protected ChangeListener changeListener
changeListener。
protected ActionListener actionListener
ActionListener。
protected ItemListener itemListener
ItemListener。
protected transient ChangeEvent changeEvent
ChangeEvent,因为事件的唯一状态是源属性。所生成的事件源总是 "this"。
| 构造方法详细信息 |
|---|
public AbstractButton()
| 方法详细信息 |
|---|
public void setHideActionText(boolean hideActionText)
hideActionText 属性,该属性确定按钮是否显示 Action 的文本。只有在按钮上已安装了 Action 时,此方法才有用。
hideActionText - 如果按钮的 text 属性不应该反映 Action 的文本,则该参数为 true;默认情况下为 falseAction 的 Swing 组件public boolean getHideActionText()
hideActionText 属性的值,该属性确定按钮是否显示 Action 的文本。只有在按钮上已安装了 Action 时,此方法才有用。
text 属性不应该反映 Action 的文本,则返回 true;默认情况下返回 falsepublic String getText()
setText(java.lang.String)public void setText(String text)
text - 用于设置文本的字符串getText()public boolean isSelected()
public void setSelected(boolean b)
actionEvent。调用 doClick 以执行程序上的动作更改。
b - 如果选择了按钮,则该参数为 true,否则为 falsepublic void doClick()
public void doClick(int pressTime)
pressTime 毫秒的时间。
pressTime - “按下”按钮的时间,以毫秒为单位public void setMargin(Insets m)
null 会造成按钮使用默认空白。按钮的默认 Border 对象将使用该值来创建适当的空白。不过,如果在按钮上设置非默认边框,则由 Border 对象负责创建适当的空白(否则此属性将被忽略)。
m - 边框和标签之间的间隔public Insets getMargin()
Insets 对象setMargin(java.awt.Insets)public Icon getIcon()
IconsetIcon(javax.swing.Icon)public void setIcon(Icon defaultIcon)
defaultIcon - 用作默认图像的图标getIcon(),
setPressedIcon(javax.swing.Icon)public Icon getPressedIcon()
pressedIcon 属性setPressedIcon(javax.swing.Icon)public void setPressedIcon(Icon pressedIcon)
pressedIcon - 用作“按下”图像的图标getPressedIcon()public Icon getSelectedIcon()
selectedIcon 属性setSelectedIcon(javax.swing.Icon)public void setSelectedIcon(Icon selectedIcon)
selectedIcon - 用作“选择”图像的图标getSelectedIcon()public Icon getRolloverIcon()
rolloverIcon 属性setRolloverIcon(javax.swing.Icon)public void setRolloverIcon(Icon rolloverIcon)
rolloverIcon - 用作“翻转”图像的图标getRolloverIcon()public Icon getRolloverSelectedIcon()
rolloverSelectedIcon 属性setRolloverSelectedIcon(javax.swing.Icon)public void setRolloverSelectedIcon(Icon rolloverSelectedIcon)
rolloverSelectedIcon - 用作“选择翻转”图像的图标getRolloverSelectedIcon()public Icon getDisabledIcon()
一些外观上可能没有呈现禁用图标,在这种情况下,它们将忽略此图标。
disabledIcon 属性getPressedIcon(),
setDisabledIcon(javax.swing.Icon),
LookAndFeel.getDisabledIcon(javax.swing.JComponent, javax.swing.Icon)public void setDisabledIcon(Icon disabledIcon)
disabledIcon - 用作禁用图像的图标getDisabledIcon()public Icon getDisabledSelectedIcon()
getDisabledIcon()。
一些外观上可能没有呈现禁用选择 Icon,在这种情况下,它们将忽略此图标。
disabledSelectedIcon 属性getDisabledIcon(),
setDisabledSelectedIcon(javax.swing.Icon),
LookAndFeel.getDisabledSelectedIcon(javax.swing.JComponent, javax.swing.Icon)public void setDisabledSelectedIcon(Icon disabledSelectedIcon)
disabledSelectedIcon - 用作禁用选择图像的图标getDisabledSelectedIcon()public int getVerticalAlignment()
verticalAlignment 属性,它是以下值之一:
SwingConstants.CENTER(默认值)
SwingConstants.TOP
SwingConstants.BOTTOM
public void setVerticalAlignment(int alignment)
alignment - 它是以下值之一:
SwingConstants.CENTER(默认值)
SwingConstants.TOP
SwingConstants.BOTTOM
IllegalArgumentException - 如果对齐方式不是上面列出的合法值之一public int getHorizontalAlignment()
AbstractButton 的默认对齐方式为 SwingConstants.CENTER,但子类(如 JCheckBox)可以使用不同的默认对齐方式。
horizontalAlignment 属性,它是以下值之一:
SwingConstants.RIGHT
SwingConstants.LEFT
SwingConstants.CENTER
SwingConstants.LEADING
SwingConstants.TRAILING
public void setHorizontalAlignment(int alignment)
AbstractButton 的默认对齐方式为 SwingConstants.CENTER,但子类(如 JCheckBox)可以使用不同的默认对齐方式。
alignment - 对齐方式的值,它是以下值之一:
SwingConstants.RIGHT
SwingConstants.LEFT
SwingConstants.CENTER
SwingConstants.LEADING
SwingConstants.TRAILING
IllegalArgumentException - 如果对齐方式不是有效值之一public int getVerticalTextPosition()
verticalTextPosition 属性,它是以下值之一:
SwingConstants.CENTER(默认值)
SwingConstants.TOP
SwingConstants.BOTTOM
public void setVerticalTextPosition(int textPosition)
textPosition - 它是以下值之一:
SwingConstants.CENTER(默认值)
SwingConstants.TOP
SwingConstants.BOTTOM
public int getHorizontalTextPosition()
horizontalTextPosition 属性,它是以下值之一:
SwingConstants.RIGHT
SwingConstants.LEFT
SwingConstants.CENTER
SwingConstants.LEADING
SwingConstants.TRAILING(默认值)
public void setHorizontalTextPosition(int textPosition)
textPosition - 它是以下值之一:
SwingConstants.RIGHT
SwingConstants.LEFT
SwingConstants.CENTER
SwingConstants.LEADING
SwingConstants.TRAILING(默认值)
IllegalArgumentException - 如果 textPosition 不是上面列出的合法值之一public int getIconTextGap()
setIconTextGap(int)public void setIconTextGap(int iconTextGap)
此属性的默认值为 4 个像素。
这是一个 JavaBeans 绑定属性。
getIconTextGap()
protected int checkHorizontalKey(int key,
String exception)
key 参数是否为 horizontalAlignment 和 horizontalTextPosition 属性的合法值。有效值有:
SwingConstants.RIGHT
SwingConstants.LEFT
SwingConstants.CENTER
SwingConstants.LEADING
SwingConstants.TRAILING
key - 要检查的属性值exception - IllegalArgumentException 中要使用的消息,无效值时抛出
IllegalArgumentException - 如果 key 不是上面列出的合法值之一setHorizontalTextPosition(int),
setHorizontalAlignment(int)
protected int checkVerticalKey(int key,
String exception)
key 参数是否为垂直属性的合法值。有效值有:
SwingConstants.CENTER
SwingConstants.TOP
SwingConstants.BOTTOM
key - 要检查的属性值exception - IllegalArgumentException 中要使用的消息,无效值时抛出
IllegalArgumentException - 如果 key 不是上面列出的合法值之一public void removeNotify()
KeyboardAction。
JComponent 中的 removeNotifyJComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)public void setActionCommand(String actionCommand)
actionCommand - 此按钮的动作命令public String getActionCommand()
public void setAction(Action a)
Action。新 Action 将替换所有以前设置的 Action,但不影响单独使用 addActionListener 添加的 ActionListener。如果 Action 已经是按钮的已注册 ActionListener,则它不需要重新注册。
设置 Action 导致支持 Action 的 Swing 组件中描述的所有属性立即更改。随后,按钮的属性根据 Action 的属性的更改进行自动更新。
此方法可以使用三个其他方法设置并帮助跟踪 Action 的属性值。它使用 configurePropertiesFromAction 方法可立即更改按钮的属性。要跟踪 Action 的属性值中的更改,此方法应注册 createActionPropertyChangeListener 返回的 PropertyChangeListener。Action 中的属性更改时,默认 PropertyChangeListener 调用 actionPropertyChanged 方法。
a - AbstractButton 的 Action,或为 nullAction,
getAction(),
configurePropertiesFromAction(javax.swing.Action),
createActionPropertyChangeListener(javax.swing.Action),
actionPropertyChanged(javax.swing.Action, java.lang.String)public Action getAction()
ActionEvent 源设置的 Action,如果没有设置任何 Action,则返回 null。
ActionEvent 源的 Action,或 nullAction,
setAction(javax.swing.Action)protected void configurePropertiesFromAction(Action a)
Action 中的属性。有关关于设置了哪些属性的更多信息,请参阅支持 Action 的 Swing 组件。
a - 从中获取属性的 Action,或为 nullAction,
setAction(javax.swing.Action)
protected void actionPropertyChanged(Action action,
String propertyName)
createActionPropertyChangeListener 返回的 PropertyChangeListener 中调用此方法。子类通常不需要调用此方法。支持其他 Action 属性的子类应该重写此方法以及 configurePropertiesFromAction。
有关此方法设置的属性的列表,请参阅支持 Action 的 Swing 组件处的表。
action - 与此按钮关联的 ActionpropertyName - 已更改属性的名称Action,
configurePropertiesFromAction(javax.swing.Action)protected PropertyChangeListener createActionPropertyChangeListener(Action a)
PropertyChangeListener,它负责侦听指定 Action 的更改以及更新适当的属性。
警告:如果为此类创建子类,则不要创建匿名内部类。否则,按钮的生命周期将依赖于 Action 的生命周期。
a - 按钮的操作Action,
setAction(javax.swing.Action)public boolean isBorderPainted()
borderPainted 属性。
borderPainted 属性的值setBorderPainted(boolean)public void setBorderPainted(boolean b)
borderPainted 属性。如果该属性为 true 并且按钮有边框,则绘制该边框。borderPainted 属性的默认值为 true。
b - 如果为 true 并且边框属性不为 null,则绘制该边框isBorderPainted()protected void paintBorder(Graphics g)
BorderPainted 属性为 true 并且按钮有边框,则绘制该按钮边框。
JComponent 中的 paintBorderg - 在其中进行绘制的 Graphics 环境JComponent.paint(java.awt.Graphics),
JComponent.setBorder(javax.swing.border.Border)public boolean isFocusPainted()
paintFocus 属性。
paintFocus 属性setFocusPainted(boolean)public void setFocusPainted(boolean b)
paintFocus 属性,对于要绘制的焦点状态,该属性必须为 true。paintFocus 属性的默认值为 true。一些外观没有绘制焦点状态;它们将忽略此属性。
b - 如果为 true,则应绘制焦点状态isFocusPainted()public boolean isContentAreaFilled()
contentAreaFilled 属性。
contentAreaFilled 属性setContentAreaFilled(boolean)public void setContentAreaFilled(boolean b)
contentAreaFilled 属性。如果该属性为 true,则按钮将绘制内容区域。如果希望有一个透明的按钮,比如只是一个图标的按钮,那么应该将此属性设置为 false。不要调用 setOpaque(false)。contentAreaFilled 属性的默认值为 true。
此方法可能造成组件的不透明属性发生更改。
调用此方法的具体行为在各个组件和各个 L&F 之间是各不相同的。
b - 如果为 true,则应该填充内容;如果为 false,则不填充内容区域isContentAreaFilled(),
JComponent.setOpaque(boolean)public boolean isRolloverEnabled()
rolloverEnabled 属性。
rolloverEnabled 属性的值setRolloverEnabled(boolean)public void setRolloverEnabled(boolean b)
rolloverEnabled 属性,若需要翻转效果,该属性必须为 true。rolloverEnabled 属性的默认值为 false。一些外观也许不实现翻转效果;它们将忽略此属性。
b - 如果为 true,则应绘制翻转效果isRolloverEnabled()public int getMnemonic()
public void setMnemonic(int mnemonic)
一个助记符必须对应键盘上的一个键,并且应该使用 java.awt.event.KeyEvent 中定义的 VK_XXX 键代码之一指定。助记符是不区分大小写的,所以具有相应键代码的键事件将造成按钮被激活,不管是否按下 Shift 修饰符。
如果在按钮的标签字符串中发现由助记符定义的字符,则第一个出现的助记符将是带下划线的,以向用户指示该助记符。
mnemonic - 表示助记符的键代码KeyEvent,
setDisplayedMnemonicIndex(int)public void setMnemonic(char mnemonic)
setMnemonic(int) 来设置按钮的助记符。此方法仅设计用于处理 'a' 到 'z' 或 'A' 到 'Z'之间的字符值。
mnemonic - 指定助记符值的字符setMnemonic(int)
public void setDisplayedMnemonicIndex(int index)
throws IllegalArgumentException
与助记符相关的属性发生更改时(比如助记符本身、文本……),此索引值也被更改。如果不希望默认字符带下划线,那么只能不断地调用此方法。例如,如果文本 'Save As' 带有一个助记符 'a',您想装饰 'A'(比如装饰成 'Save As'),那么您必须在调用 setMnemonic(KeyEvent.VK_A) 之后调用 setDisplayedMnemonicIndex(5)。
index - String 中的索引,指示要加下划线的字符
IllegalArgumentException - 如果 index >= 文本的长度,或者 < -1,则抛出该异常getDisplayedMnemonicIndex()public int getDisplayedMnemonicIndex()
setDisplayedMnemonicIndex(int)public void setMultiClickThreshhold(long threshhold)
threshhold - 按下鼠标到生成相应动作事件所需的时间量
IllegalArgumentException - 如果 threshhold < 0getMultiClickThreshhold()public long getMultiClickThreshhold()
setMultiClickThreshhold(long)public ButtonModel getModel()
model 属性setModel(javax.swing.ButtonModel)public void setModel(ButtonModel newModel)
newModel - 新的 ButtonModelgetModel()public ButtonUI getUI()
setUI(javax.swing.plaf.ButtonUI)public void setUI(ButtonUI ui)
ui - ButtonUI L&F 对象getUI()public void updateUI()
AbstractButton 的子类型应该重写此方法来更新 UI。例如,JButton 可以执行以下操作:
setUI((ButtonUI)UIManager.getUI(
"ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));
JComponent 中的 updateUIJComponent.setUI(javax.swing.plaf.ComponentUI),
UIManager.getLookAndFeel(),
UIManager.getUI(javax.swing.JComponent)
protected void addImpl(Component comp,
Object constraints,
int index)
Container.addImpl(Component, Object, int)。
Container 中的 addImplcomp - 要添加的组件constraints - 表示此组件的布局约束的对象index - 容器列表中插入组件的位置,-1 表示添加到列表的末尾
IllegalArgumentException - 如果 index 无效
IllegalArgumentException - 如果将容器的父容器添加到该容器自身中
IllegalArgumentException - 如果将一个窗口添加到容器中Container.add(Component),
Container.add(Component, int),
Container.add(Component, java.lang.Object),
LayoutManager,
LayoutManager2public void setLayout(LayoutManager mgr)
Container.setLayout(LayoutManager)。
Container 中的 setLayoutmgr - 指定的布局管理器Container.doLayout(),
Container.getLayout()public void addChangeListener(ChangeListener l)
ChangeListener。
l - 要添加的侦听器public void removeChangeListener(ChangeListener l)
l - 要移除的侦听器public ChangeListener[] getChangeListeners()
ChangeListener 组成的数组。
ChangeListener,如果没有添加侦听器,则返回一个空数组protected void fireStateChanged()
EventListenerListpublic void addActionListener(ActionListener l)
ActionListener 添加到按钮中。
l - 要添加的 ActionListenerpublic void removeActionListener(ActionListener l)
ActionListener。如果侦听器是按钮当前设置的 Action,则将 Action 设置为 null。
l - 要移除的侦听器public ActionListener[] getActionListeners()
ActionListener 组成的数组。
ActionListener,如果没有添加侦听器,则返回一个空数组protected ChangeListener createChangeListener()
ChangeEvent 的子类可以重写此方法,以返回另一个 ChangeListener 实现。
ChangeListenerprotected void fireActionPerformed(ActionEvent event)
event 参数以延迟方式创建事件实例。
event - ActionEvent 对象EventListenerListprotected void fireItemStateChanged(ItemEvent event)
event 参数以延迟方式创建事件实例。
event - ItemEvent 对象EventListenerListprotected ActionListener createActionListener()
protected ItemListener createItemListener()
public void setEnabled(boolean b)
JComponent 中的 setEnabledb - true 表示启用按钮,否则为 falseComponent.isEnabled(),
Component.isLightweight()@Deprecated public String getLabel()
getText 取代
String@Deprecated public void setLabel(String label)
setText(text) 取代
label - 包含文本的 Stringpublic void addItemListener(ItemListener l)
ItemListener 添加到 checkbox 中。
ItemSelectable 中的 addItemListenerl - 要添加的 ItemListenerItemEventpublic void removeItemListener(ItemListener l)
ItemListener。
ItemSelectable 中的 removeItemListenerl - 要移除的 ItemListenerItemEventpublic ItemListener[] getItemListeners()
ItemListener 组成的数组。
ItemListener,如果没有添加侦听器,则返回一个空数组public Object[] getSelectedObjects()
null。
ItemSelectable 中的 getSelectedObjectsnull
protected void init(String text,
Icon icon)
public boolean imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h)
Icon 的 Image 不等于传入的 Image img 时返回 false。
ImageObserver 中的 imageUpdateComponent 中的 imageUpdateimg - 要比较的 Imageinfoflags - 更新图像时用于重绘按钮的标志,它确定将绘制多大的区域x - x 坐标y - y 坐标w - 宽度h - 高度
false;否则返回 true。ImageObserver,
Component.imageUpdate(java.awt.Image, int, int, int, int, int)protected String paramString()
AbstractButton 的字符串表示形式。此方法仅在进行调试的时候使用,对于各个实现,所返回字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为 null。
重写 paramString 来提供有关 JFC 组件的一些特定新方面的信息。
JComponent 中的 paramStringAbstractButton 的字符串表示形式
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。