Class KButtonGroup<K extends AbstractButton>

  • Type Parameters:
    K - Type of the buttons in the group.
    All Implemented Interfaces:
    Serializable, Iterable<K>

    public class KButtonGroup<K extends AbstractButton>
    extends ButtonGroup
    implements Iterable<K>
    Extension of Swing ButtonGroup which adds the following functionality:
    • Type-safety via generics.
    • Auto-selects 1st added button.
    • Group listeners.
    • Mnemonics.
    • Access to the buttons by index.
    • Implements Iterable to iterate over buttons in the group.
    See Also:
    Serialized Form
    Implementation Note:
    Adds ItemListener to the buttons in the group.
    • Constructor Detail

      • KButtonGroup

        @SafeVarargs
        public KButtonGroup​(K... buttons)
        Constructs group with the specified buttons. The first added button will be automatically selected.
        Parameters:
        buttons - Buttons to add to the group.
      • KButtonGroup

        public KButtonGroup​(Collection<K> buttons)
        Constructs group with the specified buttons. The first added button will be automatically selected.
        Parameters:
        buttons - Buttons to add to the group.
      • KButtonGroup

        public KButtonGroup​(boolean autoSelectFirstButton)
        Constructs an empty group.
        Parameters:
        autoSelectFirstButton - If true, the first added button will be automatically selected via AbstractButton.setSelected(boolean).
    • Method Detail

      • addButton

        public void addButton​(K button)
        Parameters:
        button - Button to add to the group. Not null.
      • addButtons

        @SafeVarargs
        public final void addButtons​(K... buttons)
      • getButton

        public K getButton​(int index)
        Returns:
        Button at the specified index.
      • getSelectedButton

        public K getSelectedButton()
        Returns:
        The group's selected button or null if no button is selected.
      • getSelectedIndex

        public int getSelectedIndex()
        Returns:
        Index of the group's selected button or -1 if no button is selected.
      • setSelectedIndex

        public void setSelectedIndex​(int index)
        Parameters:
        index - Index of the button to select.
        See Also:
        getSelectedIndex()
      • getButtons

        public List<K> getButtons()
        Returns:
        Buttons of this group as unmodifiable List.
      • isAutoSelectFirstButton

        public boolean isAutoSelectFirstButton()