🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #3320

Building menus dynamically

#3320
From: Peter Steele
Date: Thu, 19 Feb 1998 00:00
32 lines
1816 bytes
I'm writing an application where the user will be able to right-click over
nodes in a TreeControl and pop-up a menu of allowed actions for that node.
The menu will be built dynamically based on the type of node the user
clicked on. Building the basic menu itself is easy enough. My problem is
setting the method that is to be executed when the user selects one of the
items in the dynamic menu. I've done this sort of thing in C++ Builder and
it's pretty straightforward--you just assign the desired function pointer to
the click event of the menu item being contructed. What's the best approach
for doing this type of thing in Java?

Here's my own analysis to date:

In looking at the code that is constructed by the JBuilder GUI when defining
a menu interactively, it appears that I need to do two things: define an
action listener for the menu item object, e.g:

    menuItem1.addActionListener(new
OmcrFrame_menuItem1_actionAdapter(this));

and provide the corresponding ActionListener class:

    class OmcrFrame_menuItem1_actionAdapter implements
java.awt.event.ActionListener { ... };

I want to be able to somehow tell the event handler which node of the tree
was clicked on to cause the menu event to occur in the first place and I'm
not sure how best to approach that.

Any advice on doing this sort of thing would be very much appreciated.

Peter Steele
Technical Details
Message-ID: <6ci97i$5ep1@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,258f768a02f33f88,start
X-Google-Attributes: gid1089d0,public
From: "Peter Steele" <peter@ats-forest.com>
Subject: Building menus dynamically
Date: 1998/02/19
Message-ID: <6ci97i$5ep1@forums.borland.com>
X-Deja-AN: 326719788
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: None
Newsgroups: borland.public.jbuilder.java.api