• Post Reply Bookmark Topic Watch Topic
  • New Topic

Prevent Popup from closing when clicking on J(CheckBox)MenuItem  RSS feed

 
Sven Farrenkopf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

I have a JPopupmenu containing JMenu's with JCheckBoxMenuItems. Evertytime I click on the Item, the Popup closes. How can I prevent that?

I guess it has sth to do with the UI of either JCheckBoxMenuItem or JPopupMenu ... but no idea what exactly to do.

Thanks in advance to whoever will answer.

Sven
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sven Farrenkopf:
Evertytime I click on the Item, the Popup closes. How can I prevent that?


Hi Sven,
Welcome to the Ranch!

What you are seeing is the expected behavior of a popup item.
To fix your problem, you can do the following:
Add you checkboxes as JCheckBoxes to panel instead of menu items and then add the panel itself to the JPopupMenu.
Needless to say, you will have to provide some UI control, say an "OK" button on the panel, clicking on which will hide the JPopupMenu.
 
Sven Farrenkopf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried it ...

The checkboxes won't react to my clicks. Their state is unchanged then.

Do I have to add a MouseListener to the checkbox? It should be default-behaviour to change the state, shouldn't it?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sven Farrenkopf:

The checkboxes won't react to my clicks.


Works for me.
Care to post your relevant code?
Mine is something like this:


Dont forget to use the CODE tags
 
Sven Farrenkopf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems it's working with a JRE 1.6.x ... but JRE 1.5.x (still our company-standard) isn't.

Thanks anyway...

Sven
 
Sven Farrenkopf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, it seems to have sth to do with this bug - just in 1.5.x

http://bugs.sun.com/bugdatabase/view_bug.do;?bug_id=5036146

My workaround is a class whose constructor should be called with every JCheckbox in the PopupMenu






Solved.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couldn't you use the source of the event instead? That way you can share one listener for multiple buttons:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!