所有类


javax.swing
类 AbstractButton

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.AbstractButton
所有已实现的接口:
ImageObserver, ItemSelectable, MenuContainer, Serializable, SwingConstants
直接已知子类:
JButton, JMenuItem, JToggleButton

public abstract class AbstractButton
   
   
   
   
   
extends JComponent
implements ItemSelectable, SwingConstants

定义按钮和菜单项的一般行为。有关更多信息,请参阅《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  classAbstractButton.AccessibleAbstractButton
          此类实现对 AbstractButton 类的可访问性支持。
protected  classAbstractButton.ButtonChangeListener
          将 ChangeListener 扩展为可序列化的。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
protected  ActionListeneractionListener
          按钮模型的 ActionListener
static StringBORDER_PAINTED_CHANGED_PROPERTY
          标识是否绘制边框。
protected  ChangeEventchangeEvent
          每个按钮实例只需要一个 ChangeEvent,因为事件的惟一状态是 source 属性。
protected  ChangeListenerchangeListener
          按钮模型的 changeListener
static StringCONTENT_AREA_FILLED_CHANGED_PROPERTY
          标识对按钮绘制的内容区域的更改。
static StringDISABLED_ICON_CHANGED_PROPERTY
          标识禁用按钮时使用的图标的更改。
static StringDISABLED_SELECTED_ICON_CHANGED_PROPERTY
          标识禁用并选定按钮时使用的图标的更改。
static StringFOCUS_PAINTED_CHANGED_PROPERTY
          标识是否在边框拥有焦点时突出显示。
static StringHORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
          标识按钮的水平对齐方式的更改。
static StringHORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
          标识按钮的横向文本位置的更改。
static StringICON_CHANGED_PROPERTY
          标识对表示该按钮的图标的更改。
protected  ItemListeneritemListener
          按钮模型的 ItemListener
static StringMARGIN_CHANGED_PROPERTY
          标识按钮的边界空白的更改。
static StringMNEMONIC_CHANGED_PROPERTY
          标识按钮的助记符中的更改。
protected  ButtonModelmodel
          确定按钮状态的数据模型。
static StringMODEL_CHANGED_PROPERTY
          标识按钮模型中的更改。
static StringPRESSED_ICON_CHANGED_PROPERTY
          标识对按下按钮时使用的图标的更改。
static StringROLLOVER_ENABLED_CHANGED_PROPERTY
          标识从启用翻转到禁用翻转或者从禁用翻转到启用翻转的更改。
static StringROLLOVER_ICON_CHANGED_PROPERTY
          标识对光标移动到按钮上时使用的图标的更改。
static StringROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
          标识对光标移动到按钮上并选定该按钮时使用的图标的更改。
static StringSELECTED_ICON_CHANGED_PROPERTY
          标识对选定按钮时使用的图标的更改。
static StringTEXT_CHANGED_PROPERTY
          标识按钮的文本中的更改。
static StringVERTICAL_ALIGNMENT_CHANGED_PROPERTY
          标识按钮的垂直对齐方式的更改。
static StringVERTICAL_TEXT_POSITION_CHANGED_PROPERTY
          标识按钮的竖向文本位置的更改。
 
从类 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()
           
 
方法摘要
 voidaddActionListener(ActionListener l)
          将一个 ActionListener 添加到按钮中。
 voidaddChangeListener(ChangeListener l)
          向按钮添加一个 ChangeListener
protected  voidaddImpl(Component comp, Object constraints, int index)
          将指定组件添加到此容器的指定索引所在的位置上,参考 Container.addImpl(Component, Object, int) 可获得此方法的完整描述。
 voidaddItemListener(ItemListener l)
          将一个 ItemListener 添加到复选框中。
protected  intcheckHorizontalKey(int key, String exception)
          验证 key 对于 horizontalAlignment 属性是否合法。
protected  intcheckVerticalKey(int key, String exception)
          确保 key 是有效的。
protected  voidconfigurePropertiesFromAction(Action a)
          该工厂方法根据 Action 实例中的值设置 ActionEvent 源的属性。
protected  ActionListenercreateActionListener()
           
protected  PropertyChangeListenercreateActionPropertyChangeListener(Action a)
          该工厂方法创建 PropertyChangeListener,用来在 Action 实例上的属性更改时更新 ActionEvent 源。
protected  ChangeListenercreateChangeListener()
          想以不同的方式处理 ChangeEvent 的子类可以重写此方法,以返回另一个 ChangeListener 实现。
protected  ItemListenercreateItemListener()
           
 voiddoClick()
          以编程方式执行“单击”。
 voiddoClick(int pressTime)
          以编程方式执行“单击”。
protected  voidfireActionPerformed(ActionEvent event)
          通知所有对此事件类型的通知感兴趣的已注册侦听器。
protected  voidfireItemStateChanged(ItemEvent event)
          通知所有对此事件类型的通知感兴趣的已注册侦听器。
protected  voidfireStateChanged()
          通知所有对此事件类型的通知感兴趣的已注册侦听器。
 ActiongetAction()
          返回当前为此 ActionEvent 源设置的 Action,如果没有设置任何 Action,则返回 null
 StringgetActionCommand()
          返回此按钮的动作命令。
 ActionListener[]getActionListeners()
          返回使用 addActionListener() 添加到此 AbstractButton 的所有 ActionListener 组成的数组。
 ChangeListener[]getChangeListeners()
          返回使用 addChangeListener() 添加到此 AbstractButton 中的所有 ChangeListener 组成的数组。
 IcongetDisabledIcon()
          返回禁用按钮时按钮使用的图标。
 IcongetDisabledSelectedIcon()
          返回禁用并选择按钮时按钮使用的图标。
 intgetDisplayedMnemonicIndex()
          以索引形式返回字符,它表示助记符字符,外观应该对其提供装饰。
 intgetHorizontalAlignment()
          返回图标和文本的水平对齐方式。
 intgetHorizontalTextPosition()
          返回文本相对于图标的横向位置。
 IcongetIcon()
          返回默认图标。
 intgetIconTextGap()
          返回此按钮中显示的文本与图标之间的间隔量。
 ItemListener[]getItemListeners()
          返回使用 addItemListener() 添加到此 AbstractButton 中的所有 ItemListener 组成的数组。
 StringgetLabel()
          已过时。 - 由 getText 取代
 InsetsgetMargin()
          返回按钮边框和标签之间的空白。
 intgetMnemonic()
          返回当前模型中的键盘助记符。
 ButtonModelgetModel()
          返回此按钮表示的模型。
 longgetMultiClickThreshhold()
          获得对按钮按下鼠标到生成相应操作事件所需的时间量(以毫秒为单位)。
 IcongetPressedIcon()
          返回按钮的按下图标。
 IcongetRolloverIcon()
          返回按钮的翻转图标。
 IcongetRolloverSelectedIcon()
          返回按钮的翻转选定图标。
 IcongetSelectedIcon()
          返回按钮的选择图标。
 Object[]getSelectedObjects()
          返回包含标签的数组(长度为 1),如果没有选择按钮,则返回 null
 StringgetText()
          返回按钮的文本
 ButtonUIgetUI()
          返回呈现此组件的 L&F 对象。
 intgetVerticalAlignment()
          返回文本和图标的垂直对齐方式。
 intgetVerticalTextPosition()
          返回文本相对于图标的纵向位置。
 booleanimageUpdate(Image img, int infoflags, int x, int y, int w, int h)
          重写的此方法在当前 IconImage 不等于传入的 Imageimg 时返回 false。
protected  voidinit(String text, Icon icon)
           
 booleanisBorderPainted()
          获得 borderPainted 属性。
 booleanisContentAreaFilled()
          获得 contentAreaFilled 属性。
 booleanisFocusPainted()
          获得 paintFocus 属性。
 booleanisRolloverEnabled()
          获得 rolloverEnabled 属性。
 booleanisSelected()
          返回按钮的状态。
protected  voidpaintBorder(Graphics g)
          如果 BorderPainted 属性为 true 并且按钮有边框,则绘制该按钮边框。
protected  StringparamString()
          返回此 AbstractButton 的字符串表示形式。
 voidremoveActionListener(ActionListener l)
          从按钮中移除一个 ActionListener
 voidremoveChangeListener(ChangeListener l)
          从按钮中移除一个 ChangeListener。
 voidremoveItemListener(ItemListener l)
          从按钮中移除一个 ItemListener
 voidsetAction(Action a)
          设置 ActionEvent 源的 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
 voidsetHorizontalAlignment(int alignment)
          设置图标和文本的水平对齐方式。
 voidsetHorizontalTextPosition(int textPosition)
          设置文本相对于图标的横向位置。
 voidsetIcon(Icon defaultIcon)
          设置按钮的默认图标。
 voidsetIconTextGap(int iconTextGap)
          如果图标和文本的属性都已设置,则此属性定义图标和文本之间的间隔。
 voidsetLabel(String label)
          已过时。 - 由 setText(text) 取代
 voidsetLayout(LayoutManager mgr)
          为此容器设置布局管理器,参考 Container.setLayout(LayoutManager) 可获得此方法的完整描述。
 voidsetMargin(Insets m)
          设置按钮边框和标签之间的空白。
 voidsetMnemonic(char mnemonic)
          此方法现在已废弃,请使用 setMnemonic(int) 来设置按钮的助记符。
 voidsetMnemonic(int mnemonic)
          设置当前模型上的键盘助记符。
 voidsetModel(ButtonModel newModel)
          设置此按钮表示的模型。
 voidsetMultiClickThreshhold(long threshhold)
          设置对按钮按下鼠标到生成相应操作事件所需的时间量(以毫秒为单位)。
 voidsetPressedIcon(Icon pressedIcon)
          设置按钮的按下图标。
 voidsetRolloverEnabled(boolean b)
          设置 rolloverEnabled 属性,若需要翻转效果,该属性必须为 true
 voidsetRolloverIcon(Icon rolloverIcon)
          设置按钮的翻转图标。
 voidsetRolloverSelectedIcon(Icon rolloverSelectedIcon)
          设置按钮的翻转选择图标。
 voidsetSelected(boolean b)
          设置按钮的状态。
 voidsetSelectedIcon(Icon selectedIcon)
          设置按钮的选择图标。
 voidsetText(String text)
          设置按钮的文本。
 voidsetUI(ButtonUI ui)
          设置呈现此组件的 L&F 对象。
 voidsetVerticalAlignment(int alignment)
          设置图标和文本的垂直对齐方式。
 voidsetVerticalTextPosition(int textPosition)
          设置文本相对于图标的纵向位置。
 voidupdateUI()
          将 UI 属性重置为当前外观中的一个值。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, transferFocusBackward, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

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
标识按钮的竖向文本位置的更改。

另请参见:
常量字段值