I was looking at these two examples and I was curious what the difference is between JCheckBox and JCheckBoxMenuItem.

http://www.macs.hw.ac.uk/cs/java-swing-guidebook/?name=JMenuBar&page=3
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/CheckBoxDemoProject/src/components/CheckBoxDemo.java

These pictures make it look they are the same except JCheckBox is not in a menu but it is easy to add to a menu with the menu_name.add(menu_item) command. Is that correct?

http://www.javaperspective.com/menus.html
http://www.tutorialspoint.com/swing/swing_jcheckbox.htm

Recommended Answers

JCheckBox is for in any Panel or JFrame, JCheckBoxMenuItem is specifically for when you want a JCheckBox in a menu.

Jump to Post

if you have done it, you know the answer to your question.

Jump to Post

All 5 Replies

JCheckBox is for in any Panel or JFrame, JCheckBoxMenuItem is specifically for when you want a JCheckBox in a menu.

Will I get any weird errors with using JCheckBox in a menu? I have done that and it seems to be working.

if you have done it, you know the answer to your question.

Your right :(. Keyboard shortcuts don't work the way you would expect. This method won't work.

    red1.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_X, ActionEvent.ALT_MASK));

You would have to use this method of keyboard shortcuts.

leftJustify.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit
    .getDefaultToolkit().getMenuShortcutKeyMask()));

http://www.java2s.com/Code/Java/Swing-JFC/Aquickdemonstrationofcheckboxmenuitems.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.