This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Adding different popupmenus to different jtree nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding different popupmenus to different jtree nodes" Watch "Adding different popupmenus to different jtree nodes" New topic
Author

Adding different popupmenus to different jtree nodes

pashupathi kura
Greenhorn

Joined: Jan 01, 2005
Posts: 1
I am new to swing and I would like to add different popupmenus for different nodes of a tree. Can we do this using tree mouse listeners or tree model listeners ?

I've an application which constructs a jtree initially. Once the jtree is created, I am adding a custom mouse listener to jtree. In my custom mouse listener if the event is a popup trigger, I'm displaying a popup menu for the selected node. I've different action classes for each of the popup menu actions. In once of the action classes, a new node is inserted to the tree. After the node is added, I would like to display a different popup menu to the new node. As of now, I am still able to see the old popupmenu used for the tree initially. I think this can be done as this is a normal thing for anybody using jtrees.

I would really appreciate if anyone can guide me out or give some idea of doing this.

Thanks,
pashupathi
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi,

You can do one thing add all menu items to popup menu. Before showing popup menu check which node is selected and accordingly control visibility of menu items.

Regards,
Anand


~ Anand,
SCJP 1.5, SCWCD 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding different popupmenus to different jtree nodes
 
Similar Threads
JTree: How to update nodes?
XML to DOM to JTree
Is there anyway of overriding the default signal for PopupMenus
Popupmenus staying popped up
JCheckBoxes in JTree nodes