Class LegacyTristateCheckBox

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class LegacyTristateCheckBox extends JCheckBox
Deprecated.
Replaced by TristateCheckBox.
This class is deprecated and replaced by TristateCheckBox. We will no longer provide support for this class.

Maintenance tip - There were some tricks to getting this code working:

1. You have to overwrite addMouseListener() to do nothing 2. You have to add a mouse event on mousePressed by calling super.addMouseListener() 3. You have to replace the UIActionMap for the keyboard event "pressed" with your own one. 4. You have to remove the UIActionMap for the keyboard event "released". 5. You have to grab focus when the next state is entered, otherwise clicking on the component won't get the focus. 6. You have to make a TristateDecorator as a button model that wraps the original button model and does state management.

To get notified for the state change, usually people use itemChange listener for a regular JCheckBox but for TristateCheckBox, it doesn't work very well. It would be better to use addPropertyChangeListener on PROPERTY_STATE property. It will be fired whenever the state is changed.

Author:
Dr. Heinz M. Kabutz, JIDE Software
See Also:
  • Field Details

  • Constructor Details

    • LegacyTristateCheckBox

      public LegacyTristateCheckBox(String text, Icon icon, LegacyTristateCheckBox.State initial)
      Deprecated.
    • LegacyTristateCheckBox

      public LegacyTristateCheckBox(String text, LegacyTristateCheckBox.State initial)
      Deprecated.
    • LegacyTristateCheckBox

      public LegacyTristateCheckBox(String text)
      Deprecated.
    • LegacyTristateCheckBox

      public LegacyTristateCheckBox()
      Deprecated.
  • Method Details

    • addMouseListener

      public void addMouseListener(MouseListener l)
      Deprecated.
      No one may add mouse listeners, not even Swing!
      Overrides:
      addMouseListener in class Component
    • setState

      public void setState(LegacyTristateCheckBox.State state)
      Deprecated.
      Set the new state to either SELECTED, NOT_SELECTED or DONT_CARE. If state == null, it is treated as DONT_CARE.
      Parameters:
      state - the new state
    • getState

      public LegacyTristateCheckBox.State getState()
      Deprecated.
      Return the current state, which is determined by the selection status of the model.
      Returns:
      the current state.
    • setSelected

      public void setSelected(boolean b)
      Deprecated.
      Overrides:
      setSelected in class AbstractButton
    • getNextState

      Deprecated.
      We rotate between NOT_SELECTED, SELECTED and DONT_CARE. Subclass can override this method to tell the check box what next state is. Here is the default implementation.
         if (current == NOT_SELECTED) {
             return SELECTED;
         }
         else if (current == SELECTED) {
             return DONT_CARE;
         }
         else {
             return NOT_SELECTED;
         }
       
      Parameters:
      current - the current state
      Returns:
      the next state of the current state.