Example usage for javax.swing.tree DefaultTreeCellRenderer getTextNonSelectionColor

List of usage examples for javax.swing.tree DefaultTreeCellRenderer getTextNonSelectionColor

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeCellRenderer getTextNonSelectionColor.

Prototype

public Color getTextNonSelectionColor() 

Source Link

Document

Returns the color the text is drawn with when the node isn't selected.

Usage

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);/*  w ww  .ja  v  a  2  s.co  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: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);
    }// w  ww  .j  av a 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);
}