de.hunsicker.swing
Class EmptyButtonGroup

java.lang.Object
  |
  +--javax.swing.ButtonGroup
        |
        +--de.hunsicker.swing.EmptyButtonGroup
All Implemented Interfaces:
java.io.Serializable

public class EmptyButtonGroup
extends javax.swing.ButtonGroup

Extends the standard button group to allow empty groups. Again creating a set of buttons with the same EmptyButtonGroup object means that turning 'on' one of those buttons turns 'off' all other buttons in the group. The difference between EmptyButtonGroup and ButtonGroup lies in the fact that the currently selected button can be deselected which results - in an empty group.

Note that the original documentation for ButtonGroup (as of JDK 1.3) is wrong in that the initial state of the group does depend on the state of the added buttons (They claim 'Initially, all buttons in the group are unselected').

Version:
$Revision: 1.2 $
Author:
Marco Hunsicker
See Also:
Serialized Form

Field Summary
protected  javax.swing.ButtonModel selection
          The currently selected button.
 
Fields inherited from class javax.swing.ButtonGroup
buttons
 
Constructor Summary
EmptyButtonGroup()
          Creates a new EmptyButtonGroup object.
 
Method Summary
 void add(javax.swing.AbstractButton button)
          Adds the given button to the group.
 javax.swing.ButtonModel getSelection()
          Returns the selected button model.
 boolean isSelected(javax.swing.ButtonModel model)
          Indicates whether the given button model is selected.
 void setSelected(javax.swing.ButtonModel model, boolean select)
          Sets the selected state of the given button model.
 
Methods inherited from class javax.swing.ButtonGroup
getButtonCount, getElements, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

selection

protected javax.swing.ButtonModel selection
The currently selected button. May be null if no button is selected.

Constructor Detail

EmptyButtonGroup

public EmptyButtonGroup()
Creates a new EmptyButtonGroup object.

Method Detail

setSelected

public void setSelected(javax.swing.ButtonModel model,
                        boolean select)
Sets the selected state of the given button model.

Overrides:
setSelected in class javax.swing.ButtonGroup
Parameters:
model - model that has its state changed.
select - if true selects the given model.

isSelected

public boolean isSelected(javax.swing.ButtonModel model)
Indicates whether the given button model is selected.

Overrides:
isSelected in class javax.swing.ButtonGroup
Parameters:
model - model to check.
Returns:
true if the given model is selected.

getSelection

public javax.swing.ButtonModel getSelection()
Returns the selected button model.

Overrides:
getSelection in class javax.swing.ButtonGroup
Returns:
the selected button model.

add

public void add(javax.swing.AbstractButton button)
Adds the given button to the group. If the button is selected and the group not already contains aselected button, the button will retain its selection.

Overrides:
add in class javax.swing.ButtonGroup
Parameters:
button - button to add.


Copyright © 1997-2005 Jalopy. All Rights Reserved.