Class TristateCheckBox

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.SwingConstants
    Direct Known Subclasses:
    NullTristateCheckBox

    public class TristateCheckBox
    extends javax.swing.JCheckBox
    implements java.awt.event.ActionListener
    TristateCheckBox is a check box with three states - selected, unselected and mixed (a.k.a partial selected state). Internally it uses a new class called TristateButtonModel to store the 3rd mixed state information.

    The mixed state uses a different check icon. Instead of a checked sign in the selected state as in a regular check box, we use a square sign to indicate the mixed state. On different L&Fs, it might look different. TristateCheckBox supports most of the standard L&Fs such as Windows L&F, Metal L&F, Motif L&F, Nimbus L&F, Aqua L&F etc. For most L&Fs, we use a new UIDefault "TristateCheckBox.icon" to paint in three different states. However for Aqua L&F, we actually leveraged a client property provided by Apple to display the icon for the mixed state (refer to Radar #8930094 at http://developer.apple.com/library/mac/#releasenotes/Java/JavaSnowLeopardUpdate4LeopardUpdate9RN/ResolvedIssues/ResolvedIssues.html). To make it extensible for other L&Fs who might provide a built-in mixed state for check box, we support two types of customizations.

     
    • using client property as Aqua. You can define your own client properties and use UIDefaults to tell us how to set it. For example:
    • "TristateCheckBox.icon", null, "TristateCheckBox.setMixed.clientProperty", new Object[]{"JButton.selectedState", "indeterminate"}, "TristateCheckBox.clearMixed.clientProperty", new Object[]{"JButton.selectedState", null},
    using component name. Some Synth-based L&Fs use component name to define style. If so, you can use the following two UIDefaults. For example:
  • "TristateCheckBox.setMixed.componentName", "HalfSelected", "TristateCheckBox.clearMixed.componentName", "", The correct listener for state change is ActionListener. It will be fired when the state is changed. The ItemListener is only fired when changing from selected state to unselected state or vice versa. Only ActionListener will be fired for all three states.
See Also:
Serialized Form