如何驯服 JOptionPane 对话框上的 X?
另外,现在每当我单击右上角的“X”按钮时,对话框的行为就好像我单击“确定”(对于消息)或“是”(对于问题)。当用户单击 X 时,我想要 DO_Nothing。
在代码中下面,当我单击对话框中的 X 时,它会弹出“吃!”。显然,X 充当“是”选项,但事实并非如此。
int c =JOptionPane.showConfirmDialog(null, "Are you hungry?", "1", JOptionPane.YES_NO_OPTION);
if(c==JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null, "eat!", "Order",JOptionPane.PLAIN_MESSAGE);
}
else {JOptionPane.showMessageDialog(null, "ok cool", "Order",JOptionPane.PLAIN_MESSAGE);}
Also, right now whenever I click the 'X" button on top right, the dialog boxes behaves as if I clicked OK (on messages) or YES (on questions). When the user clicks the X, I want DO_Nothing.
In the code below, when i click on the X on the dialog box, it pops out the 'eat!'. Apparently, the X is acting as 'YES' Option, which it should not.
int c =JOptionPane.showConfirmDialog(null, "Are you hungry?", "1", JOptionPane.YES_NO_OPTION);
if(c==JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null, "eat!", "Order",JOptionPane.PLAIN_MESSAGE);
}
else {JOptionPane.showMessageDialog(null, "ok cool", "Order",JOptionPane.PLAIN_MESSAGE);}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据问题的OP澄清,更改为显示如何忽略对话框上的取消按钮:
Changed to show how to ignore the cancel button on Dialog box per OP clarification of question:
您无法通过通常的 JOptionPane.show* 方法执行您想要的操作。
你必须做这样的事情:
实际禁用关闭按钮的行是:
You can't do what you want through the usual JOptionPane.show* methods.
You have to do something like this:
The line that actually disables the close button is: