Class ToggleButtonModel

All Implemented Interfaces:
ItemSelectable, Serializable, ButtonModel
Direct Known Subclasses:
WindowToggle

public class ToggleButtonModel extends JToggleButton.ToggleButtonModel
Provides all information about a toggle button. This is not only it's current on/off status (selection state in swing talk), but also the button's name, tooltip etc. Swing doesn't provide a model/action for this, so this class does it instead. Factory methods are provided to create Swing components that use this as their model.
Since:
3 Nov 2005
Author:
Mark Taylor
See Also:
  • Constructor Details

    • ToggleButtonModel

      public ToggleButtonModel(String text, Icon icon, String shortdesc)
      Constructor.
      Parameters:
      text - text to be used on buttons etc
      icon - icon to be used on buttons etc
      shortdesc - short description to be used for tool tips etc
  • Method Details

    • setText

      public void setText(String text)
      Sets the text label associated with this model.
      Parameters:
      text - button name
    • getText

      public String getText()
      Returns the text label associated with this model.
      Returns:
      button name
    • setIcon

      public void setIcon(Icon icon)
      Sets the icon associated with this model.
      Parameters:
      icon - button icon
    • getIcon

      public Icon getIcon()
      Returns the icon associated with this model.
      Returns:
      button icon
    • setDescription

      public void setDescription(String shortdesc)
      Sets the description (for tooltips etc) associated with this model.
      Parameters:
      shortdesc - description
    • getDescription

      public String getDescription()
      Returns the description (for tooltips etc) associated with this model.
      Returns:
      description
    • createButton

      public JToggleButton createButton()
      Creates and returns a normal button using this model.
      Returns:
      button
    • createToolbarButton

      public JToggleButton createToolbarButton()
      Creates and returns a button suitable for use in a toolbar using this model. The button has no text.
      Returns:
      button
    • createMenuItem

      public JCheckBoxMenuItem createMenuItem()
      Creates and returns a menu item using this model.
      Returns:
      checkbox menu item
    • createCheckBox

      public JCheckBox createCheckBox()
      Creates and returns a check box using this model.
      Returns:
      checkbox
    • createRadioButtons

      public JRadioButton[] createRadioButtons(String name0, String name1)
      Creates and returns a pair of radio buttons using this model. One unselects it, and the other selects it.
      Parameters:
      name0 - name of the Off control
      name1 - name of the On control
      Returns:
      array of (Off, On) controls
    • setSelected

      public void setSelected(boolean state)
      Sets the state of this model.
      Specified by:
      setSelected in interface ButtonModel
      Overrides:
      setSelected in class JToggleButton.ToggleButtonModel
      Parameters:
      state - on/off status
    • isSelected

      public boolean isSelected()
      Returns the state of this model.
      Specified by:
      isSelected in interface ButtonModel
      Overrides:
      isSelected in class JToggleButton.ToggleButtonModel
      Returns:
      on/off status
    • fireActionPerformed

      public void fireActionPerformed(ActionEvent evt)
      Overrides:
      fireActionPerformed in class DefaultButtonModel