问题标签 [jmenubar]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
678 浏览

java - JFrame 上的 JMenuBar 中的空 JMenuItems

我在使用 JMenuBar 创建 JFrame 时遇到问题。我在这里有一个 MenuBarBuilder 类:

JFrame 是在另一个类中创建的:

显示 后JFrame,所有 MenuItems 都是空的,但存在并且函数 ( ActionExit) 也正常工作。JMenuItem使用以下代码设置新的menuFile.add(new JMenuItem("Exit"));按预期工作,并且 JFrame 具有正确的JMenuBar. 为什么会这样???

编辑:这是刚刚退出程序的 ActionExit 类:

0 投票
2 回答
12962 浏览

java - JMenuBar、JMenu 和 JMenuItem 的高度

是否可以使用 UIManager 为所有菜单设置一次 JMenuBar、JMenu 和 JMenuItem 的高度?

我目前正在使用:

但我觉得这不是最好的方法。

0 投票
3 回答
1251 浏览

java - JCheckBoxMenuItem 默认值

我正在尝试向我的程序添加一个选项菜单,使用 JCheckBoxMenuItems 可以更改选项。无论这些选项的值是什么,都会在程序关闭时保存到文件中。当程序启动并读取设置为布尔值的值时,将读取文件。(即,如果读取的值为 true,则项目旁边会出现一个复选标记,如果值为 false,则不存在复选标记) .

这是我到目前为止所拥有的:

如何设置默认值,PropertyChangeListener 是否正确使用?

0 投票
0 回答
233 浏览

java - JFrame和Menu中的JPanel不会失去焦点

我有一个带有 的 JFrame JMenuBar,在 JFrame 内部有一个 JPanel(面板占据了除菜单栏之外的所有空间)。问题是,当我将鼠标悬停在某个 MenuItem 上并将鼠标移动到 JPanel 并单击时,菜单应该缩回(我的意思是当您在菜单中选择 ex.File 时,它​​会显示子菜单,当您移动鼠标移动到窗口的另一个位置,然后单击子菜单隐藏/撤回)。

0 投票
1 回答
162 浏览

java - 如何添加主文件之外的 Swing 组件?

我的问题示例:

我有一个主文件:

我有一个外部对象,我试图将其添加为 JMenuBar:

但是,我的菜单栏根本没有出现。当我在主文件中创建一个 JMenuBar 函数时,例如... createMenuBar() 并在其中包含相同的确切代码,当我将它添加到框架时它会显示出来,但是当我将它作为外部对象时,它没有。

我究竟做错了什么?

编辑:修复了错误。参考上面的代码。

0 投票
1 回答
254 浏览

java - JMenuBars 不能与 setComponentZOrder() 一起使用吗?

这是一个测试类,我有两个 JPanel 和一个 JMenuBar(我在测试其他东西时覆盖了这些类,这些类确实有效)。不幸的是,当我尝试使用 setComponentZOrder() 时,JMenuBar 不再出现。当 setComponentZOrder() 部分被注释掉时,它工作得很好。

任何帮助是极大的赞赏。

0 投票
2 回答
2469 浏览

java - 如何将 JMenu 动态添加到 JMenuBar

以下是我的代码。

我想要做的是在单击菜单 item1 时向菜单栏添加菜单。该行System.out.println(mb.getMenuCount());打印正在添加菜单项。(单击菜单 item1 时会打印 2,3,4)但菜单不会显示在菜单栏中。

我应该怎么做才能使动态添加的菜单项显示在菜单栏上?我正在使用 Java 1.6。

0 投票
1 回答
148 浏览

java - Java - JMenuBar 没有出现在 JApplet 中,但它在作为应用程序运行时出现

我正在开发一个可以作为 JApplet 和应用程序运行的计算器。当我将代码作为应用程序运行时,会显示菜单栏。但是当我将它作为 JApplet 运行时,它不会。

这是 JApplet 限制吗?因为当我将所有代码(新的 JMenuBar、添加按钮等)放在计算器类中时,它就可以工作了。但是使用我自己的静态方法 MenuBar.create(),它做同样的事情并返回一个 JMenuBar,它不起作用。

这是代码,也许我忘记了使菜单栏不出现在小程序中的东西?

计算器

0 投票
1 回答
822 浏览

java - JMenu is not deselected automatically

I am working on a java project where I use some swing components. I have a problem with the JMenuBar. I have a class that extends the JMenuBar. It is functional, it as couple of JMenu objects and couple of JMenuItems in each of it. The problem is that in some situations after I select a JMenu, it is not deselected automatically. For example if I select a JMenu (when a JMenu is selected its JMenuItems becomes visible like a list) and press alt+tab on the keyboard, JFrame object that has the JMenuBar gets hidden, but the JMenu stands still on the screen. Another situation is that, when I select a JMenu and move the main JFrame using mouse, the frame gets moved but JMenu doesn't get deselected nor moved, again stands still. I will put some images and my code to be more explanatory.

This is the scenario of pressing alt+tab after selecting a menu -- This is unwanted:

http://i.imgur.com/0qL2pdD.png)

This is the scenario of moving the main JFrame with mouse right after selecting a JMenu -- This is also unwanted:

http://i.imgur.com/c0BL4dE.png

And here is my source code for my custom JMenuBar class:

And here is my source code where I use my custom JMenuBar:

I searched for hours on google, but no luck. Any help is appreciated.

0 投票
3 回答
1279 浏览

java - 带有隐藏 JMenu 下拉列表的 JMenuBar

想创建一个JMenuBar。如果window-JFrame.width 小到显示JMenuBar 的所有JMenu,JMenuBar 中会出现一个Button,所有隐藏的JMenu 都可以在下拉列表中选择。请问我怎样才能意识到呢?