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?
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:
Joined: Jun 13, 2009
However, I want the menu itself to act as the trigger
Then use a JButton, which is the proper component for this.