private static void drawSelection(JTree tree, Graphics g, final int width) { int y = 0; final int[] rows = tree.getSelectionRows(); final int height = tree.getRowHeight(); for (int row : rows) { final TreeCellRenderer renderer = tree.getCellRenderer(); final Object value = tree.getPathForRow(row).getLastPathComponent(); if (value == null) continue; final Component component = renderer.getTreeCellRendererComponent(tree, value, false, false, false, row, false); if (component.getFont() == null) { component.setFont(tree.getFont()); } g.translate(0, y); component.setBounds(0, 0, width, height); boolean wasOpaque = false; if (component instanceof JComponent) { final JComponent j = (JComponent) component; if (j.isOpaque()) wasOpaque = true; j.setOpaque(false); } component.paint(g); if (wasOpaque) { ((JComponent) component).setOpaque(true); } y += height; g.translate(0, -y); } }
@Override public Component getTreeCellRendererComponent( final JTree tree, final Object value, final boolean isSelected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { final JComponent c = (JComponent) renderer.getTreeCellRendererComponent( tree, value, isSelected, expanded, leaf, row, hasFocus); HighLightableWraps.clear(); HighLightableWraps.addAll(HighLightWraps); if (value instanceof RSInterfaceWrap) { for (int i = 0; i < HighLightableWraps.size(); i++) { NextInterface = HighLightableWraps.get(i); if (NextInterface.getComp() == null) { if (NextInterface.getChild().getInterface().getIndex() == ((RSInterfaceWrap) value).wrapped.getIndex()) { c.setForeground(Color.blue); } } } } if (value instanceof RSComponentWrap) { for (int i = 0; i < HighLightableWraps.size(); i++) { NextInterface = HighLightableWraps.get(i); if (NextInterface.getComp() == null) { if (NextInterface.getChild().getInterface().getIndex() == ((RSComponentWrap) value).wrapped.getInterface().getIndex()) { if (NextInterface.getChild().getIndex() == ((RSComponentWrap) value).wrapped.getIndex()) { c.setForeground(Color.blue); } } } else { if (NextInterface.getChild().getIndex() == ((RSComponentWrap) value).wrapped.getParent().getIndex() && NextInterface.getParent().getIndex() == ((RSComponentWrap) value).wrapped.getParent().getInterface().getIndex()) { c.setForeground(Color.blue); } } } } return c; }