[英]JFrame does not draw content, only shows white rectangle, when made visible inside ActionListener
我有一個應用程序,在顯示Jframe的開頭,用戶輸入必須進行分析的網頁的URL,然后單擊“確定”。
當用戶單擊OK時,actionListener應該執行以下操作:它應顯示一個新的Jframe,其文本為“請稍等,分析網站,這可能需要一點時間”,然后應啟動analyticsPage()方法。
問題是用戶單擊“確定”按鈕后,將顯示新的Jframe,但它是空白的,僅內部帶有白色矩形。 僅在analyticsPage()方法完成之后(幾秒鍾之后),才會顯示Jframe的內容。
static class OKListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
new WaitFrame();
// mf is main frame (the first frame where url was entered and where OK was clicked)
mf.setEnabled(false);
address = mf.getURLtext();
analyzePage();
}
}
public class WaitFrame extends JFrame {
public WaitFrame() {
super();
JFrame wait = this;
JLabel jl = new JLabel("Čakajte prosím, analyzujem stránku, môže to chvíľu trvať.");
JPanel jp = new JPanel();
jp.add(jl);
wait.getContentPane().add(jp);
wait.pack();
wait.setVisible(true);
}
}
在AWT線程中運行JFrame:
//...
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame waitFrame = new JFrame();
//...
waitFrame.pack();
waitFrame.setVisible(true);
}
});
//...
// Other things to do ...
// dispose Frame after all, if neccessry ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.