Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I prevent a JMenuItem from closing a JMenu when I click on it?

843806Feb 11 2009 — edited Feb 13 2009
Currently i am using a
this.doClick()
on an ActionEvent to reopen the menu after click, but this creates an unwanted flicker effect. My best guess would be to use the focusGained/focusLost to check whether the menu is being used and use that to paint or unpaint my PopupMenu (
this.setPopupMenuVisible(b);
), but I have not tried as I was hoping there was a better solution. I could not find one with a cursory check of the forums.

Also on that note, I am also getting some painting issues. Currently I have a ActionEvent listener on a CheckBox that removes and adds components to the same menu depending on what is clicked, this creates a blank screen that is only visible when exiting and reentering the menu. Using doClick() it vaguely updates correctly, however there are certain times when it does not work correctly. Any suggestions would be appreciated.

Edited by: his_oWn on Feb 11, 2009 8:12 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 13 2009
Added on Feb 11 2009
6 comments
1,176 views