tags:

views:

56

answers:

3
+1  Q: 

Java Menu issue

I have a menu with a few JCheckBoxMnuItems. How do I ensure that the Menu stays open until I have done all my selections (i.e. checked the menuitems) and does not close on just clicking one of them?

+1  A: 

I guess menu's aren't supposed to allow multi-selection. But you may offer keyboard shortcuts to set the menuitems without using the menu at all.

If the set-operation of your flags is a central aspect in your application, I would tend to use a dialog here. These are all suggestions which do not require to change the internal implementation of the existing controls, even though I know, that it would be possible in swing.

pimpf0r
+2  A: 

I'd rather not try to change the normal menu behavior for an application or for a part of the menu tree. A User expects that the menu closes automatically after a menu item is clicked. And, if you kept the menu expanded, what kind of action would you invent to close it manually after you've done your last selection?

If there's a requirement to change more then one setting within one use case, then you should consider to provide a small dialog where the use can apply the changes and confirm them at once. I believe, that's more consistent with typical behaviors of UIs.

And it declutters the menu bar, you'll have just one 'setup' menu item instead of a dozen (?) check box actions :)

Andreas_D
Thanks for retranslating my posting to make points more clearly. What would I do without your help? ;)
pimpf0r
Ah com'on, I just didn't read you answer carefully. After the post I realized, that it was exactly your advise, but I didn't want to delete it. +1 from me for your answer :)
Andreas_D
After reading *your* post more carefully I just realized one must be more explanatory when answering questions.
pimpf0r
A: 

I agree that it is better to do this with standard UI. However, if do you want to add checkboxes that do not close the menu it is surprisingly easy:

JCheckBox checkBox = new JCheckBox("Text");
checkBox.setOpaque(false);
checkBox.setRequestFocusEnabled(false);
menu.add(checkBox);

This may not work on every look and feel and the check boxes will not line up with menu items in the same manner as JMenuItems but it seems to be a reasonable place to start.

Russ Hayward