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
@JavaBean(description="A component which can display it\'s state as selected or deselected.") public class JRadioButton extends JToggleButton implements Accessible
单选按钮的实现 -- 一个可以被选中或取消选中的项目,并向用户显示其状态。与
ButtonGroup
对象一起使用,以创建一组一次只能选择一个按钮的按钮。(创建一个 ButtonGroup 对象,并使用其 add
方法将 JRadioButton 对象包含在组中。)
注意: ButtonGroup 对象是逻辑分组 -- 而不是物理分组。要创建一个按钮面板,您仍应创建一个JPanel
或类似的容器对象,并向其添加一个Border
来使其与周围组件区分开来。
按钮可以通过 Action
进行配置,并在一定程度上受控。使用 Action
与按钮有许多优点,超出了直接配置按钮。有关更多详细信息,请参阅 支持 Action
的 Swing 组件,您可以在 The Java Tutorial 的 如何使用 Actions 部分找到更多信息。
请参阅 The Java Tutorial 中的 如何使用按钮、复选框和单选按钮 以获取更多文档。
警告: Swing 不是线程安全的。有关更多信息,请参阅 Swing 的线程策略。
警告: 该类的序列化对象将不兼容未来的 Swing 版本。当前的序列化支持适用于短期存储或在运行相同版本的 Swing 应用程序之间进行 RMI。从 1.4 版开始,已将所有 JavaBeans 的长期存储支持添加到 java.beans
包中。请参阅 XMLEncoder
。
- 自版本:
- 1.2
- 参见:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
该类实现了对JRadioButton
类的辅助功能支持。Nested classes/interfaces declared in class javax.swing.JToggleButton
JToggleButton.AccessibleJToggleButton, JToggleButton.ToggleButtonModel
Nested classes/interfaces declared in class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields declared in class 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
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields declared in interface 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
-
Constructor Summary
ConstructorDescription创建一个初始未选中且没有设置文本的单选按钮。JRadioButton
(String text) 创建一个带有指定文本的未选中单选按钮。JRadioButton
(String text, boolean selected) 创建一个具有指定文本和选择状态的单选按钮。JRadioButton
(String text, Icon icon) 创建一个具有指定文本和图像且初始未选中的单选按钮。JRadioButton
(String text, Icon icon, boolean selected) 创建一个具有指定文本、图像和选择状态的单选按钮。创建一个从提供的 Action 中获取属性的单选按钮。JRadioButton
(Icon icon) 创建一个初始未选中且具有指定图像但没有文本的单选按钮。JRadioButton
(Icon icon, boolean selected) 创建一个具有指定图像和选择状态但没有文本的单选按钮。 -
Method Summary
Modifier and TypeMethodDescriptionGets the AccessibleContext associated with this JRadioButton.Returns the name of the L&F class that renders this component.protected String
Returns a string representation of this JRadioButton.void
updateUI()
Resets the UI property to a value from the current look and feel.Methods declared in class javax.swing.JToggleButton
requestFocus, requestFocusInWindow
Methods declared in class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, 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, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
Methods declared in class 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, 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
Methods declared in class 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
Methods declared in class 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, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JRadioButton
public JRadioButton()Creates an initially unselected radio button with no set text. -
JRadioButton
Creates an initially unselected radio button with the specified image but no text.- 参数:
-
icon
- 按钮应显示的图像
-
JRadioButton
创建一个从提供的 Action 中获取属性的单选按钮。- 参数:
-
a
- 一个Action
- 自版本:
- 1.3
-
JRadioButton
创建一个具有指定图像和选择状态但没有文本的单选按钮。- 参数:
-
icon
- 按钮应显示的图像 -
selected
- 如果为 true,则按钮最初被选中;否则,按钮最初未选中
-
JRadioButton
创建一个带有指定文本的未选中单选按钮。- 参数:
-
text
- 单选按钮上显示的字符串
-
JRadioButton
创建一个具有指定文本和选择状态的单选按钮。- 参数:
-
text
- 单选按钮上显示的字符串 -
selected
- 如果为 true,则按钮最初被选中;否则,按钮最初未选中
-
JRadioButton
创建一个具有指定文本和图像且初始未选中的单选按钮。- 参数:
-
text
- 单选按钮上显示的字符串 -
icon
- 按钮应显示的图像
-
JRadioButton
创建一个具有指定文本、图像和选择状态的单选按钮。- 参数:
-
text
- 单选按钮上显示的字符串 -
icon
- 按钮应显示的图像 -
selected
- 如果为true
,则按钮最初被选中;否则,按钮最初未选中
-
-
Method Details
-
updateUI
public void updateUI()重置 UI 属性为当前外观的值。- 覆盖:
-
updateUI
在类JToggleButton
中 - 参见:
-
getUIClassID
@BeanProperty(bound=false, expert=true, description="A string that specifies the name of the L&F class.") public String getUIClassID()返回渲染此组件的 L&F 类的名称。- 覆盖:
-
getUIClassID
在类JToggleButton
中 - 返回:
- 字符串 "RadioButtonUI"
- 参见:
-
paramString
返回此 JRadioButton 的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null
。- 覆盖:
-
paramString
在类JToggleButton
中 - 返回:
- 此 JRadioButton 的字符串表示形式。
-
getAccessibleContext
@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this Button") public AccessibleContext getAccessibleContext()获取与此 JRadioButton 关联的 AccessibleContext。对于 JRadioButtons,AccessibleContext 采用 AccessibleJRadioButton 的形式。如有必要,将创建一个新的 AccessibleJRadioButton 实例。- 指定者:
-
getAccessibleContext
在接口Accessible
中 - 覆盖:
-
getAccessibleContext
在类JToggleButton
中 - 返回:
- 作为此 JRadioButton 的 AccessibleContext 的 AccessibleJRadioButton
-