[英]How to remove minimize button and keep maximize and close button in JFrame
[英]How to minimize a jFrame when the window close button is pressed?
我想在按下关闭按钮时最小化 JFrame,我正在使用下面显示的代码,但是每当我按下关闭按钮时,框架首先最小化然后自动关闭。 我在 Ubuntu 上工作。
如何防止 JFrame 关闭?
public class MainClass {
public static void main(String args[]) throws ClassNotFoundException {
final Gui frame = new Gui();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
frame.setExtendedState(Frame.ICONIFIED);
}
});
}
}
试试这种方式
final Gui frame = new Gui();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);// <- prevent closing
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
frame.setExtendedState(JFrame.ICONIFIED);
}
});
frame.setSize(200,200);
frame.setVisible(true);
这将防止窗口关闭,并且您当前的代码会将其最小化(至少这是它在 Win7 上的工作方式,让我知道它是否有帮助)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.