コード例 #1
0
  @Override
  public final Component getTreeCellRendererComponent(
      JTree tree,
      Object value,
      boolean selected,
      boolean expanded,
      boolean leaf,
      int row,
      boolean hasFocus) {
    myTree = tree;

    clear();

    mySelected = selected;
    myFocusedCalculated = false;

    // We paint background if and only if tree path is selected and tree has focus.
    // If path is selected and tree is not focused then we just paint focused border.
    if (UIUtil.isFullRowSelectionLAF()) {
      setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
    } else if (WideSelectionTreeUI.isWideSelection(tree)) {
      setPaintFocusBorder(false);
      if (selected) {
        setBackground(
            hasFocus
                ? UIUtil.getTreeSelectionBackground()
                : UIUtil.getTreeUnfocusedSelectionBackground());
      }
    } else if (selected) {
      setPaintFocusBorder(true);
      if (isFocused()) {
        setBackground(UIUtil.getTreeSelectionBackground());
      } else {
        setBackground(null);
      }
    } else {
      setBackground(null);
    }

    if (value instanceof LoadingNode) {
      setForeground(JBColor.GRAY);
      setIcon(LOADING_NODE_ICON);
    } else {
      setForeground(tree.getForeground());
      setIcon(null);
    }

    if (UIUtil.isUnderGTKLookAndFeel()) {
      super.setOpaque(false); // avoid nasty background
      super.setIconOpaque(false);
    } else if (UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus) {
      super.setOpaque(false); // avoid erasing Nimbus focus frame
      super.setIconOpaque(false);
    } else if (WideSelectionTreeUI.isWideSelection(tree)) {
      super.setOpaque(false); // avoid erasing Nimbus focus frame
      super.setIconOpaque(false);
    } else {
      super.setOpaque(
          myOpaque
              || selected && hasFocus
              || selected && isFocused()); // draw selection background even for non-opaque tree
    }

    if (tree.getUI() instanceof WideSelectionTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
      setMyBorder(null);
      setIpad(new Insets(0, 2, 0, 2));
    }

    customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

    return this;
  }
コード例 #2
0
 @Override
 public void setOpaque(boolean isOpaque) {
   myOpaque = isOpaque;
   super.setOpaque(isOpaque);
 }