Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change style (color, font) of a single JTree node

I have two JTree in two panels in a JFrame. I want to change the style(color and font) of nodes on drag and drop from one tree to the other.Please provide me a way to change the color of a JTree node permanently.

enter image description here

like image 273
soumitra chatterjee Avatar asked Apr 11 '12 18:04

soumitra chatterjee


1 Answers

To start, you will need to have a data object that can handle style and color. You could subclass DefaultMutableTreeNode and add these data items with getts and setters

Then you'd need to create a custom TreeCellRenderer. I recommend extending DefaultTreeCellRenderer, and in the overridden handler, checking for your custom class, and modifying the JLabel output to use the Font and Color if these values are set

like image 196
ControlAltDel Avatar answered Oct 19 '22 01:10

ControlAltDel