我正在构建一个文本编辑器,但我不知道如何处理自动创建的 Swing 退出按钮上的监听器。 我想在用户不保存文件时使用对话框,例如按退出按钮。
最佳答案
final JFrame f = new JFrame("Good Location & Size");
// make sure the exit operation is correct.
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent we) {
// pop the dialog here, and if the user agrees..
System.exit(0);
}
});
如本文所示 answer to Best practice for setting JFrame locations ,它在退出之前序列化帧位置和大小。
关于java - 处理自动创建的退出按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43950628/