JTree: setRowHeight(int rowHeight)
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
public class MainClass {
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);
}
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);
}
}
Related examples in the same category
1. | Tree.closedIcon | | |
2. | Tree.collapsedIcon | | |
3. | Tree.expandedIcon | | |
4. | Tree.leafIcon | | |
5. | Tree.openIcon | | |
6. | JTree.DynamicUtilTreeNode: createChildren(DefaultMutableTreeNode parent, Object children) | | |
7. | new JTree() | | |
8. | new JTree(TreeNode root) | | |
9. | new JTree(Vector vector) | | |
10. | JTree: addTreeSelectionListener(TreeSelectionListener tsl) | | |
11. | JTree: addTreeWillExpandListener(TreeWillExpandListener tel) | | |
12. | JTree: convertValueToText(Object v,boolean s,boolean e,boolean l,int r,boolean h) | | |
13. | JTree: getCellRenderer() | | |
14. | JTree: getLeadSelectionRow() | | |
15. | JTree: getMaxSelectionRow() | | |
16. | JTree: getMinSelectionRow() | | |
17. | JTree: getNextMatch(String prefix, int startingRow, Bias bias) | | |
18. | JTree: getPathForLocation(int x, int y) | | |
19. | JTree: getRowHeight() | | |
20. | JTree: getSelectionRows() | | |
21. | JTree: putClientProperty('JTree.lineStyle', 'None') | | |
22. | JTree: setAutoscrolls(boolean b) | | |
23. | JTree: setCellEditor(TreeCellEditor editor) | | |
24. | JTree: setExpandedState(TreePath path, boolean state) | | |
25. | JTree: setTransferHandler(TransferHandler newHandler) (Drag and drop files from file explore) | | |