JMenuItem shows checkbox on the left, how to disable it?
Question
I'm building a drop down menu which resides in program menu bar and pops up a JPopupMenu if a JButton gets clicked. In the JPopupMenu there are multiple JMenuItems.
However, beside every JMenuItem it shows a checkbox! Which looks like this:
I don't think it should, and there is explicit JCheckBoxMenuItem for that.
Does anyone know why a check box appears in a JMenuItem and how do I disable / remove it?
The code
ImageIcon icon = ViewUtilities.createIcon("resource/gui/mainMenu.png", _buttonLength);
setIcon(icon);
JMenuItem menuItem = new JMenuItem("New Whiteboard");
menuItem.addActionListener(new NewWhiteboardActionListener());
getMenu().add(menuItem);
menuItem = new JMenuItem("Open...");
menuItem.addActionListener(new OpenFileActionListener());
getMenu().add(menuItem);
menuItem = new JMenuItem("Preferences...");
menuItem.addActionListener(new PreferencesActionListener());
getMenu().addSeparator();
getMenu().add(menuItem);
menuItem = new JMenuItem("Exit");
menuItem.addActionListener(new ExitActionListener());
getMenu().addSeparator();
getMenu().add(menuItem);
where getMenu()
returns a JPopupMenu
.
Thanks!
Cheers,
Shuo
Edit: I've fixed it. The problem is on Jide
library. I've used it
for a custom LAF of TabbedPanel. And it injects LAF for popup menus
too as long as it's load.
So the solution is too set it to don't load menu styles.
LookAndFeelFactory.installJideExtension(
LookAndFeelFactory.VSNET_STYLE_WITHOUT_MENU);
Solution 2
The problem is on Jide
library. I've used it
for a custom LAF of TabbedPanel. And it injects LAF for popup menus
too as long as it's load.
So the solution is too set it to don't load menu styles.
LookAndFeelFactory.installJideExtension(
LookAndFeelFactory.VSNET_STYLE_WITHOUT_MENU);
OTHER TIPS
@zavie Based on this jide forum topic the solution is, when using Jide to do the following before instatiating your menus
LookAndFeelFactory.installDefaultLookAndFeel();
LookAndFeelFactory.installJideExtension();
Furthermore, on Windows 7, the menu bar will have a slightly different background color than the menu items, the solution is to use JideMenu instead of JMenu.