Java JOptionPane.showConfirmDialog 热键
我正在使用 JOptionPane.showConfirmDialog 在 Java 中显示确认对话框。该对话框向用户显示是否确认。调用方式如下:
int result = JOptionPane.showConfirmDialog(sessionObjects.getActiveComponent(),
"Are you sure you want to exit?", "My App", JOptionPane.YES_NO_OPTION);
问题是,这是一个简单的确认,用户是否可以按y表示是,按n表示否?目前用户必须点击按钮?
谢谢,
安德斯
I am displaying a confirmation dialog in Java using JOptionPane.showConfirmDialog. The dialog shows a Yes No confirmation to the user. This is called as follows:
int result = JOptionPane.showConfirmDialog(sessionObjects.getActiveComponent(),
"Are you sure you want to exit?", "My App", JOptionPane.YES_NO_OPTION);
The question is as this is a simple confirmation, can the user press y for yes and n for no? At present the user has to click on the buttons?
Thanks,
Andez
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
还有另一种更简单的可能性:您可以在程序中按 alt ,然后以相同的方式释放它:
然后当您调用时:
行为完全相同,如您所愿......
There is another simpler possibility: you can press alt in a program and then release it in a same way:
then when you call:
the behavior is exactly the same, as you desired...
您已经有按钮的“热键”(助记符):Alt+Y 表示“是”,Alt+N kbd> 表示“否”。
您还可以按 Tab 在它们之间切换,并按 空格 进行切换。
You already have "hotkeys" (mnemonics) for the buttons: Alt+Y for "Yes" and Alt+N for "No".
You can also hit Tab to toggle between them and Space to press.
不,但您可以创建自己的 JDialog 来做到这一点。
No, but you can create your own JDialog that could do that.
查看停止自动对话框关闭
Look at Stopping Automatic Dialog Closing