aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Whats the best way to change background of treeNode in JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Whats the best way to change background of treeNode in JTree" Watch "Whats the best way to change background of treeNode in JTree" New topic
Author

Whats the best way to change background of treeNode in JTree

Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Greetings Ranchers,

I'm trying to change the background of a treeNode to get a hovering effect on mouseOver(); evrything seems to work so far...except I'm updating my whole tree UI; this is causing flickering of my cursor.

Is there another way of changing the background of tree node without whole tree updateUI() ?



I would appreciate any suggestions/solutions/workarounds.

TIA
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Thanks Craig,

Actually your solution is neat especially if selections are based on MouseMotions. I should have been clearer in my problem description and saved you some trouble.

Unfortunately my tree is bit more complicated:
1> I select a node only on single click; I have TreeSelectionListener there
2> I do something more on double-Click; so I need a MouseAdapter
3> I need a hovering effect under drag & drop; I dont want to select the node unless the actual drop happens

Nevertheless I found tree.getRowForLocation(e.getX(), e.getY() helpful ; I realized that the rectangle sorrounding a path can be found using getPathBounds.



Hope it helps somebody looking to achieve a hovering Effect.

Ravi

[ August 30, 2005: Message edited by: Ravi Sathish ]
[ August 30, 2005: Message edited by: Ravi Sathish ]
 
jQuery in Action, 2nd edition
 
subject: Whats the best way to change background of treeNode in JTree
 
Similar Threads
JLabel setBackround
Treenode image
JTree Row Background Colour
Custom Icons in JTree
What is the best way to create GUI components- in-line, methods, inner classes or separate classes