JMenuItem 在左侧显示复选框,如何禁用它?
我正在构建一个下拉菜单,该菜单位于程序菜单栏中,如果单击 JButton,则会弹出 JPopupMenu。在 JPopupMenu 中有多个 JMenuItem。
然而,在每个 JMenuItem 旁边,它显示一个复选框!看起来像这样:
我认为不应该,并且有明确的 JCheckBoxMenuItem 。
有谁知道为什么 JMenuItem 中出现一个复选框以及如何禁用/删除它?
代码
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);
getMenu()
返回 JPopupMenu
的
。谢谢!
干杯,
Shuo
编辑:我已经修好了。问题出在 Jide
库上。我用过 用于 TabbedPanel 的自定义 LAF。它为弹出菜单注入 LAF 只要有负载。
因此,解决方案是将其设置为不加载菜单样式。
LookAndFeelFactory.installJideExtension(
LookAndFeelFactory.VSNET_STYLE_WITHOUT_MENU);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@zavie基于这个jide论坛主题解决方案是,当在初始化菜单之前使用 Jide 执行以下操作
此外,在 Windows 7 上,菜单栏的背景颜色与菜单项的背景颜色略有不同,解决方案是使用 JideMenu 而不是 JMenu。
@zavie Based on this jide forum topic the solution is, when using Jide to do the following before instatiating your menus
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.
问题出在
Jide
库上。我用过用于 TabbedPanel 的自定义 LAF。它为弹出菜单注入 LAF
只要有负载。
因此,解决方案是将其设置为不加载菜单样式。
The problem is on
Jide
library. I've used itfor 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.