问题
I need to stop the default operation of window being closed when red x mark is clicked on the swing window. I am using the JDialog and adding WindowsListener to it to capture the WindowClosing event, there I decide whether to dispose JDialog or to not dispose it, I am also setting the following:
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
But still when I click on the red x mark, the window closes. Any ideas?
回答1:
Adding Window listener to the JDialog gave me the power to handle the window actions and I works fine in my application.
回答2:
You can try creating a WindowListener and do nothing when the close buttion is clicked.
jdialog.addWindowListener(new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
}
});
来源:https://stackoverflow.com/questions/9924835/setdefaultcloseoperation-not-working-in-swing