Class CheckBoxTreeCellRenderer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, TreeCellRenderer

public class CheckBoxTreeCellRenderer extends JPanel implements TreeCellRenderer, Serializable
Renderers an item in a tree using JCheckBox.
See Also:
  • Field Details

    • _checkBox

      protected TristateCheckBox _checkBox
      The checkbox that is used to paint the check box in cell renderer
    • _emptyBox

      protected JComponent _emptyBox
    • _protoType

      protected JCheckBox _protoType
    • _actualTreeRenderer

      protected TreeCellRenderer _actualTreeRenderer
      The label which appears after the check box.
  • Constructor Details

    • CheckBoxTreeCellRenderer

      public CheckBoxTreeCellRenderer()
      Constructs a default renderer object for an item in a list.
    • CheckBoxTreeCellRenderer

      public CheckBoxTreeCellRenderer(TreeCellRenderer renderer)
    • CheckBoxTreeCellRenderer

      public CheckBoxTreeCellRenderer(TreeCellRenderer renderer, TristateCheckBox checkBox)
  • Method Details

    • createCheckBox

      protected TristateCheckBox createCheckBox()
      Create the check box in the cell.

      By default, it creates a TristateCheckBox and set opaque to false.

      Returns:
      the check box instance.
    • getActualTreeRenderer

      public TreeCellRenderer getActualTreeRenderer()
    • setActualTreeRenderer

      public void setActualTreeRenderer(TreeCellRenderer actualTreeRenderer)
    • getTreeCellRendererComponent

      public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
      Specified by:
      getTreeCellRendererComponent in interface TreeCellRenderer
    • updateCheckBoxState

      protected void updateCheckBoxState(TristateCheckBox checkBox, TreePath path, CheckBoxTreeSelectionModel selectionModel)
      Updates the check box state based on the selection in the selection model. By default, we check if the path is selected. If yes, we mark the check box as TristateCheckBox.SELECTED. If not, we will check if the path is partially selected, if yes, we set the check box as null or TristateCheckBox.DONT_CARE to indicate the path is partially selected. Otherwise, we set it to TristateCheckBox.NOT_SELECTED.
      Parameters:
      checkBox - the TristateCheckBox for the particular tree path.
      path - the tree path.
      selectionModel - the CheckBoxTreeSelectionModel.
    • getToolTipText

      public String getToolTipText(MouseEvent event)
      Overrides:
      getToolTipText in class JComponent