File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Exiting on menuSelected action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Exiting on menuSelected action" Watch "Exiting on menuSelected action" New topic
Author

Exiting on menuSelected action

Ben Ram
Greenhorn

Joined: Oct 13, 2009
Posts: 2
Hi all

I'm writing a simple swing screen for my Dad. He's a bit of a technophobe (by that I mean a lot of a technophobe), so I'm trying to keep it really, really simple.

I've added some click options as menus, such that when he clicks the menu the event springs into life. I could go down the whole menu ITEMS route but, like I said, keeping it really simple. I've got this:



When I click the menu, the load happens, but within a few seconds the whole program exits, no stacktrace or anything. I don't have the luxury of a debugger where I am at the moment so I don't know quite how far it's getting. Anyway, is there something I need to do to stop the whole damn thing disintegrating when the menu is clicked?

Thanks
Ben
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
Start by reading the JMenu API and follow the link to the Swing tutorial on "How to Use Menus".

You should NOT be using a MenuListener for this. You SHOULD be use an ActionListener.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
Be Forthright When Cross Posting To Other Sites
Ben Ram
Greenhorn

Joined: Oct 13, 2009
Posts: 2
Rob Camick wrote:Start by reading the JMenu API and follow the link to the Swing tutorial on "How to Use Menus".

You should NOT be using a MenuListener for this. You SHOULD be use an ActionListener.


Thanks for the response Rob. I've worked out why the above is happening but I'm still interested in how to make this work cleanly. I have read the above tutorial, and from it I gathered that ActionListener is the correct way to handle events on menu items. However, I want the menu itself to act as the trigger, or button, and adding an actionListener to the menu doesn't seem to work:


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
However, I want the menu itself to act as the trigger


Then use a JButton, which is the proper component for this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Exiting on menuSelected action