简体   繁体   English

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

[英]JFrame does not draw content, only shows white rectangle, when made visible inside ActionListener

I have an application, on the beginning the Jframe is displayed, user enters the URL of a webpage that has to be analysed, then user clicks OK. 我有一个应用程序,在显示Jframe的开头,用户输入必须进行分析的网页的URL,然后单击“确定”。

When user clicks OK actionListener should do this: It should display a new Jframe with a text "please wait , analysing website, this may take a little" then it should start the analyzePage() method. 当用户单击OK时,actionListener应该执行以下操作:它应显示一个新的Jframe,其文本为“请稍等,分析网站,这可能需要一点时间”,然后应启动analyticsPage()方法。

the problem is that after user clicks OK button, the new Jframe is displayed, but it is blank, only with white rectangle inside. 问题是用户单击“确定”按钮后,将显示新的Jframe,但它是空白的,仅内部带有白色矩形。 Only after analyzePage() method is finished (which is after many seconds) Contents of Jframe are displayed. 仅在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);
}
}

Run your JFrame within the AWT-Thread: 在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