繁体   English   中英

当在ActionListener中可见时,JFrame不绘制内容,仅显示白色矩形

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM