Package jahuwaldt.swing
Class JButtonGroup
- java.lang.Object
-
- javax.swing.ButtonGroup
-
- jahuwaldt.swing.JButtonGroup
-
- All Implemented Interfaces:
java.io.Serializable
public class JButtonGroup extends javax.swing.ButtonGroup
Extendsjavax.swing.ButtonGroupto provide methods that allow working with button references instead of button models. Modified by Joseph A. Huwaldt, Date: February 23, 2025- Version:
- 1.0 April 2003
- Author:
- Daniel Tofan
- See Also:
ButtonGroup, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JButtonGroup()Creates an emptyJButtonGroupJButtonGroup(javax.swing.AbstractButton[] buttons)Creates aJButtonGroupobject from an array of buttons and adds the buttons to the group No button will be selected initially.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(javax.swing.AbstractButton button)Adds a button to the groupvoidadd(javax.swing.AbstractButton[] buttons)Adds an array of buttons to the groupbooleancontains(javax.swing.AbstractButton button)Checks whether the group contains the given buttonjavax.swing.AbstractButtongetButton(javax.swing.ButtonModel model)Returns theAbstractButtonwhoseButtonModelis given.java.util.List<javax.swing.AbstractButton>getButtons()Returns the buttons in the group as aListjavax.swing.AbstractButtongetPreviousSelected()Returns the button that was selected prior to the currently selected button in the group.javax.swing.AbstractButtongetSelected()Returns the selected button in the group.booleanisEnabled()Returns true if any button in this button group is enabled.booleanisSelected(javax.swing.AbstractButton button)Returns whether the button is selectedvoidremove(javax.swing.AbstractButton button)Removes a button from the groupvoidremove(javax.swing.AbstractButton[] buttons)Removes all the buttons in the array from the groupvoidsetEnabled(boolean flag)Enables or disables all the buttons in this button group.voidsetSelected(javax.swing.AbstractButton button, boolean selected)Sets the selected button in the group Only one button in the group can be selectedvoidsetSelected(javax.swing.ButtonModel model, boolean selected)Sets the selected button model in the group
-
-
-
Constructor Detail
-
JButtonGroup
public JButtonGroup()
Creates an emptyJButtonGroup
-
JButtonGroup
public JButtonGroup(javax.swing.AbstractButton[] buttons)
Creates aJButtonGroupobject from an array of buttons and adds the buttons to the group No button will be selected initially.- Parameters:
buttons- an array ofAbstractButtons
-
-
Method Detail
-
add
public void add(javax.swing.AbstractButton button)
Adds a button to the group- Overrides:
addin classjavax.swing.ButtonGroup- Parameters:
button- anAbstractButtonreference
-
add
public final void add(javax.swing.AbstractButton[] buttons)
Adds an array of buttons to the group- Parameters:
buttons- an array ofAbstractButtons
-
remove
public void remove(javax.swing.AbstractButton button)
Removes a button from the group- Overrides:
removein classjavax.swing.ButtonGroup- Parameters:
button- the button to be removed
-
remove
public void remove(javax.swing.AbstractButton[] buttons)
Removes all the buttons in the array from the group- Parameters:
buttons- an array ofAbstractButtons
-
setSelected
public void setSelected(javax.swing.AbstractButton button, boolean selected)
Sets the selected button in the group Only one button in the group can be selected- Parameters:
button- anAbstractButtonreferenceselected- anbooleanrepresenting the selection state of the button
-
setSelected
public void setSelected(javax.swing.ButtonModel model, boolean selected)
Sets the selected button model in the group- Overrides:
setSelectedin classjavax.swing.ButtonGroup- Parameters:
model- aButtonModelreferenceselected- anbooleanrepresenting the selection state of the button
-
getButton
public javax.swing.AbstractButton getButton(javax.swing.ButtonModel model)
Returns theAbstractButtonwhoseButtonModelis given. If the model does not belong to a button in the group, returns null.- Parameters:
model- aButtonModelthat should belong to a button in the group- Returns:
- an
AbstractButtonreference whose model ismodelif the button belongs to the group,nullotherwise
-
getSelected
public javax.swing.AbstractButton getSelected()
Returns the selected button in the group.- Returns:
- a reference to the currently selected button in the group or
nullif no button is selected
-
getPreviousSelected
public javax.swing.AbstractButton getPreviousSelected()
Returns the button that was selected prior to the currently selected button in the group.- Returns:
- a reference to the button selected prior to the currently
selected button in the group or
nullif no button was selected prior to the currently selected button.
-
isSelected
public boolean isSelected(javax.swing.AbstractButton button)
Returns whether the button is selected- Parameters:
button- anAbstractButtonreference- Returns:
trueif the button is selected,falseotherwise
-
getButtons
public java.util.List<javax.swing.AbstractButton> getButtons()
Returns the buttons in the group as aList- Returns:
- a
Listcontaining the buttons in the group, in the order they were added to the group
-
contains
public boolean contains(javax.swing.AbstractButton button)
Checks whether the group contains the given button- Parameters:
button- The button to search for in this button group.- Returns:
trueif the button is contained in the group,falseotherwise
-
setEnabled
public void setEnabled(boolean flag)
Enables or disables all the buttons in this button group.- Parameters:
flag- set totrueto enable all the buttons in this group orfalseto disable them.
-
isEnabled
public boolean isEnabled()
Returns true if any button in this button group is enabled.- Returns:
trueif any button in this group is enabled.
-
-