/** * UpdateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. final TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr; // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // renderer.setBorderSelectionColor(null); renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground")); renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground")); } }
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."); }
/** * UpdateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. final TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr; // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // renderer.setBorderSelectionColor(null); renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground")); renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer to * match that of the table. */ public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer to * match that of the table. */ public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor ("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor ("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor ("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor ("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor ("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor ("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor ("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor ("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor ("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor ("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. // dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor ("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor ("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer to * match that of the table. */ @Override public void updateUI () { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is // null. dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground")); } } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. // TODO JW: need to revisit... // a) the "real" of a JXTree is always wrapped into a DelegatingRenderer // consequently the if-block never executes // b) even if it does it probably (?) should not // unconditionally overwrite custom selection colors. // Check for UIResources instead. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is null. dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor( UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor( UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. // TODO JW: need to revisit... // a) the "real" of a JXTree is always wrapped into a DelegatingRenderer // consequently the if-block never executes // b) even if it does it probably (?) should not // unconditionally overwrite custom selection colors. // Check for UIResources instead. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is null. dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor( UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor( UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. // TODO JW: need to revisit... // a) the "real" of a JXTree is always wrapped into a DelegatingRenderer // consequently the if-block never executes // b) even if it does it probably (?) should not // unconditionally overwrite custom selection colors. // Check for UIResources instead. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is null. dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor( UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor( UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. // TODO JW: need to revisit... // a) the "real" of a JXTree is always wrapped into a DelegatingRenderer // consequently the if-block never executes // b) even if it does it probably (?) should not // unconditionally overwrite custom selection colors. // Check for UIResources instead. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is null. dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor( UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor( UIManager.getColor("Table.selectionBackground")); } }
/** * updateUI is overridden to set the colors of the Tree's renderer * to match that of the table. */ @Override public void updateUI() { super.updateUI(); // Make the tree's cell renderer use the table's cell selection // colors. // TODO JW: need to revisit... // a) the "real" of a JXTree is always wrapped into a DelegatingRenderer // consequently the if-block never executes // b) even if it does it probably (?) should not // unconditionally overwrite custom selection colors. // Check for UIResources instead. TreeCellRenderer tcr = getCellRenderer(); if (tcr instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr); // For 1.1 uncomment this, 1.2 has a bug that will cause an // exception to be thrown if the border selection color is null. dtcr.setBorderSelectionColor(null); dtcr.setTextSelectionColor( UIManager.getColor("Table.selectionForeground")); dtcr.setBackgroundSelectionColor( UIManager.getColor("Table.selectionBackground")); } }
renderer.setBackgroundNonSelectionColor(color); renderer.setBorderSelectionColor(color); renderer.setTextSelectionColor(Color.BLACK);
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)); } } }