JMenuItem shows checkbox on the left, how to disable it?

浪尽此生 提交于 2019-12-08 11:37:52

问题


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

回答1:


@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.




回答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);


来源:https://stackoverflow.com/questions/3656387/jmenuitem-shows-checkbox-on-the-left-how-to-disable-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!