public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { final java.awt.Component c = ren.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (selected || !drawStripes) return c; if (!(c instanceof javax.swing.tree.DefaultTreeCellRenderer)) c.setBackground(rowColors[row & 1]); else ((javax.swing.tree.DefaultTreeCellRenderer) c).setBackgroundNonSelectionColor(rowColors[row & 1]); return c; }
tree = new JTree(root); if (tree.getCellRenderer() instanceof DefaultTreeCellRenderer) { final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer)(tree.getCellRenderer()); renderer.setBackgroundNonSelectionColor(Color.YELLOW); renderer.setBackgroundSelectionColor(Color.ORANGE); renderer.setTextNonSelectionColor(Color.RED); renderer.setTextSelectionColor(Color.BLUE); } else { System.err.println("Sorry, no special colors today."); }
public void valueChanged(TreeSelectionEvent e) { JTree tree = (JTree) e.getSource(); tree.getSelectionModel().clearSelection(); if (currentSelection != null) { currentSelection.setBackground(white); ((DefaultTreeCellRenderer) currentSelection.getCellRenderer()).setBackgroundNonSelectionColor(white); } currentSelection = tree; currentSelection.setBackground(selectionColor); ((DefaultTreeCellRenderer) currentSelection.getCellRenderer()).setBackgroundNonSelectionColor(selectionColor); }
public void valueChanged(TreeSelectionEvent e) { JTree tree = (JTree) e.getSource(); tree.getSelectionModel().clearSelection(); if (currentSelection != null) { currentSelection.setBackground(white); ((DefaultTreeCellRenderer) currentSelection.getCellRenderer()).setBackgroundNonSelectionColor(white); } }
customIconRenderer.setBackgroundSelectionColor(Color.blue); customIconRenderer.setBorderSelectionColor(Color.black); customIconRenderer.setBackgroundNonSelectionColor(new Color(238, 238, 244)); ImageIcon icon = createImageIcon("http://i.stack.imgur.com/wCF8S.png");
dtcr.setBackgroundNonSelectionColor(background);
private void initDefaultRenderer() { // ui setup // init JTree // Set the icon for leaf nodes. defaultRenderer = new DefaultTreeCellRenderer(); if (leafComponentIcon != null) { defaultRenderer.setMinimumSize( new Dimension(leafComponentIcon.getIconWidth(), leafComponentIcon.getIconHeight())); defaultRenderer.setLeafIcon(leafComponentIcon); titleLabel.setIcon(leafComponentIcon); iconHeight = leafComponentIcon.getIconHeight(); defaultRenderer.setClosedIcon(closedIcon); defaultRenderer.setOpenIcon(openedIcon); // sets tree background defaultRenderer.setBackgroundNonSelectionColor( backgroundNonSelectionColor); defaultRenderer.setTextNonSelectionColor(textColor); defaultRenderer.setBackground(VSwingUtil.TRANSPARENT_COLOR); backgroundSelectionColor = defaultRenderer.getBackgroundSelectionColor(); } else { System.err.println("Leaf icon missing; using default."); } }
field.setBackground(bg); tree.setBackground(bg); ((DefaultTreeCellRenderer)tree.getCellRenderer()).setBackgroundNonSelectionColor(bg);
final DefaultTreeCellRenderer renderer = createNodeRenderer(); renderer.setBackground(background); renderer.setBackgroundNonSelectionColor(background);
} else { dtcr.setTextNonSelectionColor(component.getForeground()); dtcr.setBackgroundNonSelectionColor(component .getBackground());
checkBoxTree.setBackground(color); renderer.setBackgroundSelectionColor(color); renderer.setBackgroundNonSelectionColor(color); renderer.setBorderSelectionColor(color); renderer.setTextSelectionColor(Color.BLACK);
} else { dtcr.setTextNonSelectionColor(component.getForeground()); dtcr.setBackgroundNonSelectionColor(component .getBackground());
} else { dtcr.setTextNonSelectionColor(component.getForeground()); dtcr.setBackgroundNonSelectionColor(component .getBackground());
checkBoxTree.setBackground(color); renderer.setBackgroundSelectionColor(color); renderer.setBackgroundNonSelectionColor(color); renderer.setBorderSelectionColor(color); renderer.setTextSelectionColor(Color.BLACK);
} else { dtcr.setTextNonSelectionColor(component.getForeground()); dtcr.setBackgroundNonSelectionColor(component .getBackground());
} else { dtcr.setTextNonSelectionColor(component.getForeground()); dtcr.setBackgroundNonSelectionColor(component .getBackground());
dtcr.setBackgroundNonSelectionColor(background);
protected void installDefaults() { super.installDefaults(); if(tree.getCellRenderer() instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)tree.getCellRenderer(); r.setBackgroundNonSelectionColor(Theme.treeTextBgColor.getColor()); r.setBackgroundSelectionColor(Theme.treeSelectedBgColor.getColor()); r.setTextNonSelectionColor(Theme.treeTextColor.getColor()); r.setTextSelectionColor(Theme.treeSelectedTextColor.getColor()); UIDefaults defaults = UIManager.getDefaults(); r.setClosedIcon(defaults.getIcon("Tree.closedIcon")); r.setOpenIcon(defaults.getIcon("Tree.openIcon")); r.setLeafIcon(defaults.getIcon("Tree.leafIcon")); } } }
private void configureRenderer(SeaGlassContext context) { TreeCellRenderer renderer = tree.getCellRenderer(); if (renderer instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) renderer; SeaGlassStyle style = (SeaGlassStyle)context.getStyle(); context.setComponentState(ENABLED | SELECTED); Color color = r.getTextSelectionColor(); if (color == null || (color instanceof UIResource)) { r.setTextSelectionColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); } color = r.getBackgroundSelectionColor(); if (color == null || (color instanceof UIResource)) { r.setBackgroundSelectionColor(style.getColor(context, ColorType.TEXT_BACKGROUND)); } context.setComponentState(ENABLED); color = r.getTextNonSelectionColor(); if (color == null || color instanceof UIResource) { r.setTextNonSelectionColor(style.getColorForState(context, ColorType.TEXT_FOREGROUND)); } color = r.getBackgroundNonSelectionColor(); if (color == null || color instanceof UIResource) { r.setBackgroundNonSelectionColor(style.getColorForState(context, ColorType.TEXT_BACKGROUND)); } } }
renderer.setBackgroundNonSelectionColor(background);