If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

adding different popupmenus to different tree nodes

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.

Are we talking popup menu as in like right-clicking to bring up a menu?
Either way, inside the listener you should grab the node that was clicked. Determine the type or status of the node and then show the appropriate menu.