JMenuItem 在左侧显示复选框,如何禁用它?

发布于 2024-09-18 11:57:45 字数 1427 浏览 7 评论 0原文

我正在构建一个下拉菜单,该菜单位于程序菜单栏中,如果单击 JButton,则会弹出 JPopupMenu。在 JPopupMenu 中有多个 JMenuItem。

然而,在每个 JMenuItem 旁边,它显示一个复选框!看起来像这样:

alt text

我认为不应该,并且有明确的 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:

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ら栖息 2024-09-25 11:57:45

@zavie基于这个jide论坛主题解决方案是,当在初始化菜单之前使用 Jide 执行以下操作

LookAndFeelFactory.installDefaultLookAndFeel();
LookAndFeelFactory.installJideExtension();

此外,在 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

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.

两相知 2024-09-25 11:57:45

问题出在 Jide 库上。我用过
用于 TabbedPanel 的自定义 LAF。它为弹出菜单注入 LAF
只要有负载。

因此,解决方案是将其设置为加载菜单样式。

LookAndFeelFactory.installJideExtension(
  LookAndFeelFactory.VSNET_STYLE_WITHOUT_MENU);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文