Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

popup menus

Thread view: 
google@aikempshall.freeserve.co.uk - 20 Jan 2006 10:29 GMT
I have a popup menu which shows itself when I right click over a
JTextArea called taLocations. I can use the menu with the following
ActionListener. Within the same frame I have another JTextArea called
taSkills which will utilise the same popup menu.

As you will see in the code I want to identify the name of the
JTextArea that the popup menu was "hovering" over. How?

      ActionListener menuListener = new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               System.out.println("ActionListener");
               System.out.println(event.getActionCommand());

    System.out.println(event.getSource().getClass().getName());
                 System.out.println(event.getClass().getName());
               if (event.getActionCommand().equalsIgnoreCase("Save"))
{

               }

               if
(event.getActionCommand().equalsIgnoreCase("Restore")) {
                   System.out.println(event.getSource());
                    restoreFilter("locations");
               }
           }
       };
Raymond DeCampo - 22 Jan 2006 02:25 GMT
> I have a popup menu which shows itself when I right click over a
> JTextArea called taLocations. I can use the menu with the following
[quoted text clipped - 23 lines]
>             }
>         };

There are many ways to do this.  The most straight forward might be to
make your ActionListener a named class and add an attribute to hold the
name of the text area.  Then when the menu pops, it is responsible for
setting the attribute.  You could also have the attribute on the pop-up
menu object.

Alternatively you could use different instances of pop-up menu and
listeners that already know what text area they are associated to.

HTH,
Ray

Signature

This signature intentionally left blank.

google@aikempshall.freeserve.co.uk - 25 Jan 2006 14:19 GMT
Thanks. I've gone for the different instances of pop-up menu and
listeners. Like so -

       ActionListener menuListenerSkills = new ActionListener() {
           public void actionPerformed(ActionEvent event) {
               if (event.getActionCommand().equalsIgnoreCase("Save"))
{

               }

               if
(event.getActionCommand().equalsIgnoreCase("Restore")) {

               }
           }
       };
       itemSkills.addActionListener(menuListenerSkills);
       popupSkills.setLabel("Justification");
       popupSkills.setBorder(new BevelBorder(BevelBorder.RAISED));
       taSkills.addMouseListener(new OpenSeatViewer().new
skillsMousePopupListener());      

Thanks


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.