如果用户点击右上角的X,我不希望发生任何事情。什么是代码行来实现这一点?JOptionPane如何禁用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无法提领
你为什么要这么做?从代码片段看来,您可能会将其视为与“NO_OPTION”相同。通常,当我关闭一个对话框时,我希望它将该操作视为取消操作。 – 2011-04-27 23:59:55