如果用戶點擊右上角的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