JavaTM 2 Platform
Standard Ed. 5.0

javax.swing
类 JRadioButton

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.AbstractButton
                  继承者 javax.swing.JToggleButton
                      继承者 javax.swing.JRadioButton
所有已实现的接口:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class JRadioButton
extends JToggleButton
implements Accessible

实现一个单选按钮,此按钮项可被选择或取消选择,并可为用户显示其状态。与 ButtonGroup 对象配合使用可创建一组按钮,一次只能选择其中的一个按钮。(创建一个 ButtonGroup 对象并用其 add 方法将 JRadioButton 对象包含在此组中。)

注:ButtonGroup 对象为逻辑分组,不是物理分组。要创建按钮面板,仍需要创建一个 JPanel 或类似的容器对象并将 Border 添加到其中以便将面板与周围的组件分开。

有关进一步的内容,请参阅《The Java Tutorial》中的 How to Use Buttons, Check Boxes, and Radio Buttons

警告:此类的序列化对象将与以后的 Swing 版本不兼容。当前的序列化支持适用于短期存储或运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder

另请参见:
ButtonGroup, JCheckBox

嵌套类摘要
protected  class JRadioButton.AccessibleJRadioButton
          此类实现对 JRadioButton 类的可访问性支持。
 
从类 javax.swing.JToggleButton 继承的嵌套类/接口
JToggleButton.AccessibleJToggleButton, JToggleButton.ToggleButtonModel
 
从类 javax.swing.AbstractButton 继承的嵌套类/接口
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
 
从类 javax.swing.AbstractButton 继承的字段
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
从类 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
 
构造方法摘要
JRadioButton()
          创建一个初始化为未选择的单选按钮,其文本未设定。
JRadioButton(Action a)
          创建一个单选按钮,其属性来自提供的 Action。
JRadioButton(Icon icon)
          创建一个初始化为未选择的单选按钮,其具有指定的图像但无文本。
JRadioButton(Icon icon, boolean selected)
          创建一个具有指定图像和选择状态的单选按钮,但无文本。
JRadioButton(String text)
          创建一个具有指定文本的状态为未选择的单选按钮。
JRadioButton(String text, boolean selected)
          创建一个具有指定文本和选择状态的单选按钮。
JRadioButton(String text, Icon icon)
          创建一个具有指定的文本和图像并初始化为未选择的单选按钮。
JRadioButton(String text, Icon icon, boolean selected)
          创建一个具有指定的文本、图像和选择状态的单选按钮。
 
方法摘要
protected  void configurePropertiesFromAction(Action a)
          该工厂方法根据 Action 实例中的值设置 ActionEvent 源的属性。
protected  PropertyChangeListener createActionPropertyChangeListener(Action a)
          该工厂方法创建 PropertyChangeListener,当属性在其 Action 实例中更改时,用于更新 ActionEvent 源。
 AccessibleContext getAccessibleContext()
          获取与此 JRadioButton 相关联的 AccessibleContext。
 String getUIClassID()
          返回呈现此组件的 L&F 类的名称。
protected  String paramString()
          返回此 JRadioButton 的字符串表示形式。
 void updateUI()
          将 UI 属性重置为当前外观对应的值。
 
从类 javax.swing.AbstractButton 继承的方法
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, 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
 

构造方法详细信息

JRadioButton

public JRadioButton()
创建一个初始化为未选择的单选按钮,其文本未设定。


JRadioButton

public JRadioButton(Icon icon)
创建一个初始化为未选择的单选按钮,其具有指定的图像但无文本。

参数:
icon - 此按钮应显示的图像

JRadioButton

public JRadioButton(Action a)
创建一个单选按钮,其属性来自提供的 Action。

从以下版本开始:
1.3

JRadioButton

public JRadioButton(Icon icon,
                    boolean selected)
创建一个具有指定图像和选择状态的单选按钮,但无文本。

参数:
icon - 此按钮应显示的图像
selected - 如果为 true,按钮被初始化为选择;否则,按钮被初始化为未选择

JRadioButton

public JRadioButton(String text)
创建一个具有指定文本的状态为未选择的单选按钮。

参数:
text - 单选按钮上显示的字符串

JRadioButton

public JRadioButton(String text,
                    boolean selected)
创建一个具有指定文本和选择状态的单选按钮。

参数:
text - 单选按钮上显示的字符串
selected - 如果为 true,按钮被初始化为选择;否则,按钮被初始化为未选择

JRadioButton

public JRadioButton(String text,
                    Icon icon)
创建一个具有指定的文本和图像并初始化为未选择的单选按钮。

参数:
text - 此单选按钮上显示的字符串
icon - 此按钮应显示的图像

JRadioButton

public JRadioButton(String text,
                    Icon icon,
                    boolean selected)
创建一个具有指定的文本、图像和选择状态的单选按钮。

参数:
text - 此单选按钮上显示的字符串
icon - 此按钮应显示的图像
方法详细信息

updateUI

public void updateUI()
将 UI 属性重置为当前外观对应的值。

覆盖:
JToggleButton 中的 updateUI
另请参见:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
返回呈现此组件的 L&F 类的名称。

覆盖:
JToggleButton 中的 getUIClassID
返回:
"RadioButtonUI" 字符串
另请参见:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

configurePropertiesFromAction

protected void configurePropertiesFromAction(Action a)
该工厂方法根据 Action 实例中的值设置 ActionEvent 源的属性。对于子类,设置的属性可能不同。默认情况下,设置的属性为 Text、Mnemonic、Enabled、ActionCommandMnemonic

覆盖:
AbstractButton 中的 configurePropertiesFromAction
参数:
a - 要从其获得属性的 Action,或为 null
从以下版本开始:
1.3
另请参见:
Action, AbstractButton.setAction(javax.swing.Action)

createActionPropertyChangeListener

protected PropertyChangeListener createActionPropertyChangeListener(Action a)
该工厂方法创建 PropertyChangeListener,当属性在其 Action 实例中更改时,用于更新 ActionEvent 源。如果子类应当保持更新的属性组不同于默认属性(Text、Icon、Enabled、ToolTipText),则可以重写此方法以提供它们自己的 PropertyChangeListener。 注意,PropertyChangeListener 应该避免保持对 ActionEvent 源的强引用,因为这可能妨碍 ActionEvent 源及其容积分层结构中所有组件的垃圾回收。

覆盖:
AbstractButton 中的 createActionPropertyChangeListener
参数:
a - 按钮的新操作
从以下版本开始:
1.3
另请参见:
Action, AbstractButton.setAction(javax.swing.Action)

paramString

protected String paramString()
返回此 JRadioButton 的字符串表示形式。此方法仅在进行调试的时候使用,对于各个实现,所返回字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为 null

覆盖:
JToggleButton 中的 paramString
返回:
此 JRadioButton 的字符串表示形式。

getAccessibleContext

public AccessibleContext getAccessibleContext()
获取与此 JRadioButton 相关联的 AccessibleContext。对于 JRadioButton,AccessibleContext 采用 AccessibleJRadioButton 的形式。必要时创建新的 AccessibleJRadioButton 实例。

指定者:
接口 Accessible 中的 getAccessibleContext
覆盖:
JToggleButton 中的 getAccessibleContext
返回:
一个 AccessibleJRadioButton,它将充当此 JRadioButton 的 AccessibleContext

JavaTM 2 Platform
Standard Ed. 5.0

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策