SingleFrameApplication 不需要 ALT 来激活菜单项助记符?
在 NetBeans 6.9 IDE 中,如果您创建 新项目>> Java>> Java桌面应用程序
并运行它,你会发现菜单项有助记符,但只有在按下ALT
之后。
(netbeans 程序本身使用这种样式的菜单。)
但是,如果您创建一个新的 File >> Swing GUI 表单>> JFrame Form
,并添加一个带有助记词的简单菜单栏,然后运行JFrame,助记词将始终出现,而无需按ALT
。这就是我想要的。
(Firefox 使用这种风格的菜单)
我的想法是 org.jdesktop.application 会覆盖默认设置,但这只是一个猜测。有人知道如何使 SingleFrameApplication 不需要按下 ALT
吗?
谢谢。
编辑: 发现问题是 JFrame 和 JDesktop 使用不同的默认外观
In the NetBeans 6.9 IDE, if you create aNew Project >> Java >> Java Desktop Application
and run it, you will find that the menu items have mnemonics, but only after ALT
is pressed.
(The netbeans program itself uses this style of menu.)
However, if you create a new File >> Swing GUI Forms >> JFrame Form
, and add a simple menubar with mnemonics, then run the JFrame, the mnemonics will always appear without having to press ALT
. This is what I would prefer.
(Firefox uses this style of menu)
My thoughts are that the org.jdesktop.application
overrides the default setting, but that's just a guess. Anyone know how to make a SingleFrameApplication not require ALT
to be pressed?
Thanks.
Edit:
The problem was found to be that JFrame and JDesktop use different default Look and Feels
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Windows 设置。在 XP 中,转到:
(我想,Win7 应该在某处有类似的设置。)
默认设置是打开的,因此 Java 是正确的,而 Firefox 是错误(甚至 Office 2003 也不尊重该设置)。
取消选中它,您将始终在 Java 中看到助记符下划线。
请注意,只有 Windows LAF 正确遵循该设置。 Motif 和 Metal 始终显示下划线。我不使用 NetBeans 或 jDesktop,但我猜它使用系统 LAF,因此下划线是正确的。
如果您仍然希望在 Windows LAF 下始终显示下划线(请三思而后行),请调用
UIManager.getLookAndFeelDefaults().put("Button.showMnemonics", false)
,这会似乎不适用于 XP,因为WindowsMenuItemUI#paintText
仅检查 Vista 下的标志。你可以自己检查一下Win7 JDK。请注意,当设置打开时,会出现已接受的错误,如下所示(为您节省一些时间来解析宇宙中第二个最糟糕的错误跟踪系统。最糟糕的是我公司曾经拥有的内部 ColdFusion 系统):使用助记符创建一个菜单,例如
&File,按
Alt-F
,松开,再按Alt-F
,下划线消失了。只要您执行任何其他操作(单击或单独按Alt
),它们就会立即返回。It's a Windows setting. In XP go to:
(Win7 should have a similar setting somewhere, I suppose.)
The default setting is on, so Java is right and Firefox is wrong (even Office 2003 doesn't respect that setting).
Uncheck it and you'll always see mnemonic underline in Java.
Note that only Windows LAF correctly respects the setting. Motif and Metal always show the underline. I don't use NetBeans or jDesktop but I guess it uses system LAF and thus the underline is correct.
If you still want to always show underline under Windows LAF (please think twice before you do), call
UIManager.getLookAndFeelDefaults().put("Button.showMnemonics", false)
, which does NOT seem to work for XP becauseWindowsMenuItemUI#paintText
only checks the flag under Vista. You could check Win7 JDK yourself.Note that there's an accepted bug when the setting is on, which goes like this (saving you some time to parse the 2nd most awful bug tracking system in the universe. The worst is an in-house ColdFusion system my company used to have): create one menu with mnemonic, for example
&File
, pressAlt-F
, release, pressAlt-F
again, the underline is gone. They are back as soon as you do anything else, clicking, or just pressAlt
by itself.