public Component getTreeCellRendererComponent(
      JTree tree,
      Object value,
      boolean selected,
      boolean expanded,
      boolean leaf,
      int row,
      boolean hasFocus) {
    Component renderer =
        delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    if (!showRootNodeCheckBox && tree.getModel().getRoot() == value) return renderer;

    TreePath path = tree.getPathForRow(row);
    if (path != null) {
      if (checkBoxCustomer != null && !checkBoxCustomer.showCheckBox(path)) return renderer;
      if (selectionModel.isPathSelected(path, selectionModel.isDigged()))
        checkBox.getTristateModel().setState(TristateState.SELECTED);
      else
        checkBox
            .getTristateModel()
            .setState(
                selectionModel.isDigged() && selectionModel.isPartiallySelected(path)
                    ? TristateState.INDETERMINATE
                    : TristateState.DESELECTED);
    }
    removeAll();
    add(checkBox, BorderLayout.WEST);
    add(renderer, BorderLayout.CENTER);
    return this;
  }
 public CheckTreeCellRenderer(
     TreeCellRenderer delegate,
     CheckTreeSelectionModel selectionModel,
     boolean showRootNodeCheckBox) {
   this.delegate = delegate;
   this.selectionModel = selectionModel;
   this.showRootNodeCheckBox = showRootNodeCheckBox;
   setLayout(new BorderLayout());
   setOpaque(false);
   checkBox.setOpaque(false);
 }
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Icon icon = (Icon) _originalIcon.createValue(UIManager.getDefaults());
    if (isSynthIcon(icon)) {
      int state = getComponentState((JComponent) c);
      if (c instanceof TristateCheckBox
          && ((TristateCheckBox) c).getModel() instanceof TristateButtonModel
          && ((TristateButtonModel) ((TristateCheckBox) c).getModel()).isMixed())
        state &= ~SynthConstants.SELECTED;
      SynthContext context =
          new SynthContext(
              (JComponent) c,
              Region.CHECK_BOX,
              SynthLookAndFeel.getStyle((JComponent) c, Region.CHECK_BOX),
              state);
      final int w = ((SynthIcon) icon).getIconWidth(context);
      final int h = ((SynthIcon) icon).getIconHeight(context);
      ((SynthIcon) icon).paintIcon(context, g, x, y, w, h);
    } else {
      if (c instanceof TristateCheckBox
          && ((TristateCheckBox) c).getModel() instanceof TristateButtonModel
          && ((TristateButtonModel) ((TristateCheckBox) c).getModel()).isMixed()) {
        ((TristateButtonModel) ((TristateCheckBox) c).getModel()).internalSetSelected(false);
      }
      icon.paintIcon(c, g, x, y);
      if (c instanceof TristateCheckBox
          && ((TristateCheckBox) c).getModel() instanceof TristateButtonModel
          && ((TristateButtonModel) ((TristateCheckBox) c).getModel()).isMixed()) {
        ((TristateButtonModel) ((TristateCheckBox) c).getModel()).internalSetSelected(true);
      }
    }

    g.setColor(UIManager.getColor("CheckBox.foreground"));
    if (c instanceof TristateCheckBox
        && ((TristateCheckBox) c).getModel() instanceof TristateButtonModel
        && ((TristateButtonModel) ((TristateCheckBox) c).getModel()).isMixed())
      drawSquare(c, g, x, y);
  }