Jframe内容未显示

时间:2012-03-29 18:00:23

标签: java swing jframe

我试图在用户点击我的应用程序中的特定按钮时在新的JFrame中显示加载图像。显示JFrame,但它没有显示任何内容!,也有白色背景,而所有JFrame都有灰色默认背景。这里有什么问题?

stop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            analyzer.running=false;
            JFrame Load1=new JFrame("Load1");
            ImageIcon icon1=new ImageIcon("./ajax-loader.gif");
            System.out.println(icon1.getIconHeight());
            Load1.add(new JLabel("Retrieving...", icon1, JLabel.CENTER),BorderLayout.CENTER);
            Load1.pack();
            Load1.setSize(400,400);
            Load1.setVisible(true);

            System.out.println("Start Processing");
            parser.parse();  // Time Consuming method


            nw_Creator.create();
            System.out.println("End Processing");
            Load1.setVisible(false);

            home.setVisible(false);
            screen2.setVisible(true);

        }
    });

2 个答案:

答案 0 :(得分:4)

不要将耗时的部分放在事件处理程序或事件派发线程中运行的任何方法中。您可能希望改为使用swing worker

答案 1 :(得分:1)

发生的事情是您永远不会发布UI线程,因此您的JFrame永远不会被绘制。由于所有图形操作都是在UI线程上完成的,因此您必须释放它,进行计算,然后在希望jframe显示任何内容时关闭帧。

相关问题