1

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?

3 Answers 3

1

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 :)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for retranslating my posting to make points more clearly. What would I do without your help? ;)
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 :)
After reading your post more carefully I just realized one must be more explanatory when answering questions.
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.