JOptionPane如何禁用X?
如果用户单击右上角的 X,我不希望发生任何事情。实现这一点的代码行是什么?
Object [] options1 = {"Go Back", "Accept"};
int a3 =JOptionPane.showOptionDialog(null,"Mean arterial pressure restored.\nReassess all vitals STAT.", "Title", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
if(a3 == JOptionPane.CLOSED_OPTION)
{
//what should i put here? if user X out, I want no response (DO_NOTHING_ON_CLOSE)
}
if(a3 == JOptionPane.YES_OPTION)
{
// doing something else
}
if (a3 == JOptionPane.NO_OPTION)
{
//doing something else
}
我尝试了类似 a3.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 但我收到错误 int Can be dereferenced
If the user clicks X on the top right, I don't want anything to happen. What is the code line to make this happen?
Object [] options1 = {"Go Back", "Accept"};
int a3 =JOptionPane.showOptionDialog(null,"Mean arterial pressure restored.\nReassess all vitals STAT.", "Title", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
if(a3 == JOptionPane.CLOSED_OPTION)
{
//what should i put here? if user X out, I want no response (DO_NOTHING_ON_CLOSE)
}
if(a3 == JOptionPane.YES_OPTION)
{
// doing something else
}
if (a3 == JOptionPane.NO_OPTION)
{
//doing something else
}
I tried something like a3.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
but I get an error int cannot be dereferenced
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了 Chris 选项之外,请查看 javadocs (http: //download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html)直接使用示例。
您可以实现您尝试过的目标:
Besides Chris option, take a look at the javadocs (http://download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html) Direct use example.
You can achieve what you have tried with:
这种简约的方法怎么样:
What about this minimalistic approach:
此代码可能会解决问题(您可以运行代码来测试它):
This code might do the trick (you can run the code to test it):