Class JButtonGroup

  • All Implemented Interfaces:
    java.io.Serializable

    public class JButtonGroup
    extends javax.swing.ButtonGroup
    Extends javax.swing.ButtonGroup to provide methods that allow working with button references instead of button models. Modified by Joseph A. Huwaldt, Date: September 16, 2012
    Version:
    1.0 April 2003
    Author:
    Daniel Tofan
    See Also:
    ButtonGroup, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      JButtonGroup()
      Creates an empty JButtonGroup
      JButtonGroup​(javax.swing.AbstractButton[] buttons)
      Creates a JButtonGroup object 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
      void add​(javax.swing.AbstractButton button)
      Adds a button to the group
      void add​(javax.swing.AbstractButton[] buttons)
      Adds an array of buttons to the group
      boolean contains​(javax.swing.AbstractButton button)
      Checks whether the group contains the given button
      javax.swing.AbstractButton getButton​(javax.swing.ButtonModel model)
      Returns the AbstractButton whose ButtonModel is given.
      java.util.List<javax.swing.AbstractButton> getButtons()
      Returns the buttons in the group as a List
      javax.swing.AbstractButton getPreviousSelected()
      Returns the button that was selected prior to the currently selected button in the group.
      javax.swing.AbstractButton getSelected()
      Returns the selected button in the group.
      boolean isEnabled()
      Returns true if any button in this button group is enabled.
      boolean isSelected​(javax.swing.AbstractButton button)
      Returns whether the button is selected
      void remove​(javax.swing.AbstractButton button)
      Removes a button from the group
      void remove​(javax.swing.AbstractButton[] buttons)
      Removes all the buttons in the array from the group
      void setEnabled​(boolean flag)
      Enables or disables all the buttons in this button group.
      void setSelected​(javax.swing.AbstractButton button, boolean selected)
      Sets the selected button in the group Only one button in the group can be selected
      void setSelected​(javax.swing.ButtonModel model, boolean selected)
      Sets the selected button model in the group
      • Methods inherited from class javax.swing.ButtonGroup

        clearSelection, getButtonCount, getElements, getSelection, isSelected
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JButtonGroup

        public JButtonGroup()
        Creates an empty JButtonGroup
      • JButtonGroup

        public JButtonGroup​(javax.swing.AbstractButton[] buttons)
        Creates a JButtonGroup object from an array of buttons and adds the buttons to the group No button will be selected initially.
        Parameters:
        buttons - an array of AbstractButtons
    • Method Detail

      • add

        public void add​(javax.swing.AbstractButton button)
        Adds a button to the group
        Overrides:
        add in class javax.swing.ButtonGroup
        Parameters:
        button - an AbstractButton reference
      • add

        public final void add​(javax.swing.AbstractButton[] buttons)
        Adds an array of buttons to the group
        Parameters:
        buttons - an array of AbstractButtons
      • remove

        public void remove​(javax.swing.AbstractButton button)
        Removes a button from the group
        Overrides:
        remove in class javax.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 of AbstractButtons
      • 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 - an AbstractButton reference
        selected - an boolean representing 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:
        setSelected in class javax.swing.ButtonGroup
        Parameters:
        model - a ButtonModel reference
        selected - an boolean representing the selection state of the button
      • getButton

        public javax.swing.AbstractButton getButton​(javax.swing.ButtonModel model)
        Returns the AbstractButton whose ButtonModel is given. If the model does not belong to a button in the group, returns null.
        Parameters:
        model - a ButtonModel that should belong to a button in the group
        Returns:
        an AbstractButton reference whose model is model if 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 null if 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 null if 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 - an AbstractButton reference
        Returns:
        true if the button is selected, false otherwise
      • getButtons

        public java.util.List<javax.swing.AbstractButton> getButtons()
        Returns the buttons in the group as a List
        Returns:
        a List containing 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
        Returns:
        true if the button is contained in the group, false otherwise
      • setEnabled

        public void setEnabled​(boolean flag)
        Enables or disables all the buttons in this button group.
      • isEnabled

        public boolean isEnabled()
        Returns true if any button in this button group is enabled.