![](/img/trans.png)
[英]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.