Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes DefaultTreeCellRenderer not highlighting TreeNode on right-click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "DefaultTreeCellRenderer not highlighting TreeNode on right-click" Watch "DefaultTreeCellRenderer not highlighting TreeNode on right-click" New topic
Author

DefaultTreeCellRenderer not highlighting TreeNode on right-click

Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
I'm using a renderer that extends DefaultTreeCellRenderer. When I left-click on a tree node, it becomes highlighted. But not on a right-click. At first I thought it was because the popupMenu was stealing the focus, but I took the menu code out and same results.

So, anyone know how to highlight a tree node when it's right-clicked?
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
Turns out, all I needed was this code in my MouseAdapter inner class:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DefaultTreeCellRenderer not highlighting TreeNode on right-click
 
Similar Threads
JPopupMenu - Help required
update the tree node
JTree node as non editable
PopUp Menu for JTree
tree display