我的代码:
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
fileMenu.setDisplayedMnemonicIndex(0);
Javadocs对于 AbstractButton.setDisplayedMnemonicIndex()
来说
Not all look and feels may support this.
我将外观设置为 UIManager.getSystemLookAndFeelClassName()
即使在 Windows 7 下通过 setDisplayedMnemonicIndex()
显式设置索引(仅当我按 ALT
时),我也看不到助记词上的下划线。
但是,如果我不设置外观和感觉并仅保留默认的 java 主题,它就会起作用。
有办法实现这一点吗?是Windows的设置造成的吗?
最佳答案
您可以通过使用 UIManager
设置属性来更改仅在按 Alt 键时显示下划线的行为
UIManager.getDefaults().put("Button.showMnemonics", Boolean.TRUE);
我认为您需要在显示第一个 Swing 组件之前执行此操作,但我不确定。
关于java - 有没有办法在Win 7下将下划线设置为 native 外观中的助记符字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18811043/