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 / October 2006

Tip: Looking for answers? Try searching our database.

trouble with popup menu

Thread view: 
Justin - 29 Sep 2006 14:56 GMT
hello again, havin a bitchin time with this popup menu I'm trying to
create.  I'm a learn by doing type of person and I havent found any
good examples of how to implement a pop-up menu.  The main class in the
application extends a JPanel.  I searched google and found the
following snippet of code and inserted it into my constructor:

           final JPopupMenu menu = new JPopupMenu();
   // Create and add a menu item
   JMenuItem item = new JMenuItem("Item Label");
   item.addActionListener(this);
   menu.add(item);

   // Set the component to show the popup menu
   this.addMouseListener(new MouseAdapter() {
       public void mousePressed(MouseEvent evt) {
           if (evt.isPopupTrigger()) {
               menu.show(evt.getComponent(), evt.getX(), evt.getY());
           }
       }
       public void mouseReleased(MouseEvent evt) {
           if (evt.isPopupTrigger()) {
               menu.show(evt.getComponent(), evt.getX(), evt.getY());
           }
       }
   });

however, this code does nothing when I run the application.  Currently,
my actionPerformed method is empty, I dont know if I have to add
anything to this method to get the popup to run or not.  I'll give it a
try, but any help would be appreciated.
tiewknvc9 - 29 Sep 2006 16:11 GMT
I think that you don't even need that whole mouselistener bit.

try adding the line...

this.setComponentPopupMenu(m_myPopUpMenu);

basically you have created a menu that is not currently being "added"
to anything, so the menu exists, but it is sleeping.

let me know if this worked for you

> hello again, havin a bitchin time with this popup menu I'm trying to
> create.  I'm a learn by doing type of person and I havent found any
[quoted text clipped - 26 lines]
> anything to this method to get the popup to run or not.  I'll give it a
> try, but any help would be appreciated.
Justin - 29 Sep 2006 19:20 GMT
eh, didnt work.   I think I got what I needed done however.  Instead of
using a Popup, I'm using a JList that appears when a clicked and
disappears when an option has been selected.

> I think that you don't even need that whole mouselistener bit.
>
[quoted text clipped - 37 lines]
> > anything to this method to get the popup to run or not.  I'll give it a
> > try, but any help would be appreciated.
Justin - 29 Sep 2006 19:40 GMT
lol, spoke to soon, that idea worked terrible.  If you have any code of
an implemented popup that I could look at, that would be great....
RedGrittyBrick - 01 Oct 2006 19:21 GMT
> lol, spoke to soon, that idea worked terrible.  If you have any code of
> an implemented popup that I could look at, that would be great....

http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup


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



©2008 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.