public class ButtonGroup extends Object implements Serializable
ButtonGroup对象创建一组按钮意味着打开“其中一个”按钮会关闭组中的所有其他按钮。 
        A ButtonGroup可以与继承自AbstractButton任何一组对象一起使用。 典型地,按钮组包含的实例JRadioButton , JRadioButtonMenuItem ,或JToggleButton 。 将JButton或JMenuItem的实例放在按钮组中是没有意义的,因为JButton和JMenuItem不实现所选状态。 
最初,组中的所有按钮都被取消选择。
有关使用按钮组的示例和进一步信息,请参阅“Java教程 ”中的 How to Use Radio Buttons 。
 警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对于所有JavaBeans的长期存储的支持已被添加到java.beans包中。 请参阅XMLEncoder 。 
| Modifier and Type | Field and Description | 
|---|---|
| protected Vector<AbstractButton> | buttons | 
| Constructor and Description | 
|---|
| ButtonGroup()
              创建一个新的 
              ButtonGroup。 | 
| Modifier and Type | Method and Description | 
|---|---|
| void | add(AbstractButton b)
              将按钮添加到组。 
             | 
| void | clearSelection()
              清除选择,使得没有选择 
              ButtonGroup中的按钮。 | 
| int | getButtonCount()
              返回组中按钮的数量。 
             | 
| Enumeration<AbstractButton> | getElements()
              返回参与此组的所有按钮。 
             | 
| ButtonModel | getSelection()
              返回所选按钮的型号。 
             | 
| boolean | isSelected(ButtonModel m)
              返回是否选择 
              ButtonModel。 | 
| void | remove(AbstractButton b)
              从组中删除按钮。 
             | 
| void | setSelected(ButtonModel m, boolean b)
              设置 
              ButtonModel的选定值。 | 
protected Vector<AbstractButton> buttons
public void add(AbstractButton b)
b - 要添加的按钮 
           public void remove(AbstractButton b)
b - 要删除的按钮 
           public void clearSelection()
ButtonGroup中的按钮。 
          public Enumeration<AbstractButton> getElements()
Enumeration 
           public ButtonModel getSelection()
public void setSelected(ButtonModel m, boolean b)
ButtonModel的选定值。 
           一次只能选择组中的一个按钮。 
          m - 
            ButtonModel 
           b - 
            true如果该按钮被选中,否则 
            false 
           public boolean isSelected(ButtonModel m)
ButtonModel 。 
          true如果按钮被选中,否则返回 
            false 
           public int getButtonCount()
 Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.