Class RadioButtonTree

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

public class RadioButtonTree extends JPanel implements CheckboxTreeCellRenderer
Example showing the implementation of a CheckboxTree with RadioButton-style checkboxes.
Author:
bigagli
See Also:
  • Field Details

  • Constructor Details

    • RadioButtonTree

      public RadioButtonTree()
  • Method Details

    • main

      public static void main(String[] args)
    • getTreeCellRendererComponent

      public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
      Description copied from interface: CheckboxTreeCellRenderer
      This method is redeclared just to underline that the implementor has to properly display the checking/graying state of value. This should go in the method parameters, but would imply changes to Swing classes that were considered unpractical. For example in DefaultCheckboxTreeCellRenderer the following code is used to get the checking/graying states:
       TreeCheckingModel checkingModel = ((CheckboxTree) tree).getCheckingModel();
       
       TreePath path = tree.getPathForRow(row);
       
       boolean enabled = checkingModel.isPathEnabled(path);
       
       boolean checked = checkingModel.isPathChecked(path);
       
       boolean greyed = checkingModel.isPathGreyed(path);
       
      You could use a QuadristateCheckbox to properly renderer the states (as in DefaultCheckboxTreeCellRenderer).
      Specified by:
      getTreeCellRendererComponent in interface CheckboxTreeCellRenderer
      Specified by:
      getTreeCellRendererComponent in interface TreeCellRenderer
      See Also:
    • isOnHotspot

      public boolean isOnHotspot(int x, int y)
      Description copied from interface: CheckboxTreeCellRenderer
      Returns whether the specified relative coordinates insist on the intended checkbox control. It is used by the CheckboxTree mouse listener to figure out whether to toggle a node or not.
      Specified by:
      isOnHotspot in interface CheckboxTreeCellRenderer