List of usage examples for javax.swing.tree DefaultTreeCellRenderer setBackgroundSelectionColor
public void setBackgroundSelectionColor(Color newColor)
From source file:TreeNodeVector.java
public static void main(final String args[]) { JFrame frame = new JFrame("JTreeSample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" }); Vector<Object> v2 = new TreeNodeVector<Object>("Three"); v2.add(System.getProperties()); v2.add(v1);/*from w ww. j ava2s. c o m*/ Object rootNodes[] = { v1, v2 }; Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes); JTree tree = new JTree(rootVector); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); Color backgroundSelection = renderer.getBackgroundSelectionColor(); renderer.setBackgroundSelectionColor(renderer.getBackgroundNonSelectionColor()); renderer.setBackgroundNonSelectionColor(backgroundSelection); Color textSelection = renderer.getTextSelectionColor(); renderer.setTextSelectionColor(renderer.getTextNonSelectionColor()); renderer.setTextNonSelectionColor(textSelection); frame.add(new JScrollPane(tree), BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Changed Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32)); int rowHeight = tree.getRowHeight(); if (rowHeight <= 0) { tree.setRowHeight(rowHeight - 1); }/* www. j a v a 2 s.c o m*/ Color backgroundSelection = renderer.getBackgroundSelectionColor(); renderer.setBackgroundSelectionColor(Color.blue); renderer.setBackgroundNonSelectionColor(backgroundSelection); // Swap text colors Color textSelection = renderer.getTextSelectionColor(); renderer.setTextSelectionColor(Color.green); renderer.setTextNonSelectionColor(textSelection); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeChangedRenderer.java
public static void main(String args[]) { JFrame frame = new JFrame("Changed Renderer"); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32)); int rowHeight = tree.getRowHeight(); if (rowHeight <= 0) { tree.setRowHeight(rowHeight - 1); }//from www . java 2 s. c o m // Swap background colors Color backgroundSelection = renderer.getBackgroundSelectionColor(); renderer.setBackgroundSelectionColor(renderer.getBackgroundNonSelectionColor()); renderer.setBackgroundNonSelectionColor(backgroundSelection); // Swap text colors Color textSelection = renderer.getTextSelectionColor(); renderer.setTextSelectionColor(renderer.getTextNonSelectionColor()); renderer.setTextNonSelectionColor(textSelection); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }