[英]Restart a JFrame after dispose
我有一個想要在操作后重新啟動的Frame的問題。 具體而言,在Frame
開始下方:
public static void startHome() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new HomeGUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
框架下方:
public HomeGUI() throws IOException, InstantiationException, IllegalAccessException {
setIconImage(Toolkit.getDefaultToolkit().getImage(ico_path));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 669, 516);
// etc...
在我的實際代碼下面,重新啟動,但是不起作用:
frame.dispose();
startHome();
在進入run()
方法之前,處理停止。 我試圖在invokeLater
之前和dispose()
之后設置frame = null
,但是不起作用。
謝謝你們
有(重新使用)兩種方式(無意重新啟動)
setIconImage()
CardLayout
確保setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
; 終止當前的JVM
正確的LayoutManager
, JComponent
必須將PreferredSize
返回給JFrame
,然后調用
JFrame.pack()
JFrame.setLocation()
JFrame.setVisisble(true)
setBounds(100, 100, 669, 516);
dispose()
或setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
與setVisible(false)
相同,您可以通過迭代Window[] wins = Window.getWindows();
數組來從當前JVM獲取所有Top-Level Containers
Window[] wins = Window.getWindows();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.