Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在尝试在 SWT 窗口(Eclipse 插件)中的按钮上设置助记符,但不幸的是,我总是遇到以下情况:
setText("&Cancel")
setText("&&Cancel")
如果您已经遇到问题,我很高兴阅读您的解决方案来解决此问题。谢谢阅读。
终于设法找到了解决办法。以下是如何模拟 ALT 击键:
private void showMnemonics() { Event event = new Event(); event.keyCode = SWT.ALT; event.type = SWT.KeyDown; Display.getDefault().post(event); }
编辑:我猜应该将以下代码添加到方法中,以释放密钥:
event.type = SWT.KeyUp; Display.getDefault().post(event);