- This topic has 3 replies, 2 voices, and was last updated 16 years, 5 months ago by Riyad Kalla.
-
AuthorPosts
-
Douglas M HurstParticipantI added a jMenu(jMenu1) to my form.
I then added a jMenuItem (jMenuItem1) to jMenu1. The text for this jMenuItem is Exit.I added
private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {
System.exit(0);
}… which DOES NOT execute when the jMenuItem (jMenuItem1 (text: Exit)) is clicked.
I then added
private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {
System.exit(0);
}… which DOES when the jMenuItem (jMenuItem1 (text: Exit)) is clicked and causes the program to exit gracefully.
I also, in designer mode, double-clicked on the accelerator key for jMenuItem1 and set it to Alt-X. When I run the program, Alt-X has no effect.
Unfortunately, the Matisse4MyEclipse (M4M) Tutorial doesn’t touch on jMenu, which would seem to be a pretty basic addition to most any Matisse/Swing main jFrame.
Is there another tutorial that you know of that would touch on these topics?
Riyad KallaMemberDoug,
These are actually Swing issues, not M4M-specific issues.The first problem is that you are support to set the actionPerformed event on MenuItems, not handle the mouse events directly because different LNFs and different components may intercept or handle the mouse events differently. The “actionPerformed” event is always fired when a item is clicked though.
Also the actionPerformed is what is executed when the keystroke is matched, which is why setting the mouse event is skpping that and making it seem like a no-op.
I created an example project for you that shows you what ou were trying to do. You can import it, run it and see what i mean. You might need to adjust your JRE lib in the build path to match whichever one is correct in your setup, then just run MainFrame and you can hit Alt-X to exit.
Attachments:
You must be logged in to view attached files.
Douglas M HurstParticipantGot it thanks!
So many years using Borland’s C++ Builder.
Riyad KallaMemberNo problem, glad it helped.
-
AuthorPosts