public class ButtonGroup extends Object implements Serializable
ButtonGroup
对象创建一组按钮意味着转折”“其中的一个按钮关闭该组中的所有其他按钮。
一个ButtonGroup
可与任何一组对象继承自AbstractButton
。通常一个按钮组包含JRadioButton
,JRadioButtonMenuItem
,或JToggleButton
实例。它不会把JButton
或JMenuItem
实例在一个按钮组有意义因为JButton
和JMenuItem
不执行选定的状态。
最初,该组中的所有按钮被选中。
例如,进一步的信息使用按钮组看到How to Use Radio Buttons,java教程中的一部分。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为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.