简体   繁体   English

Jframe内容未显示

[英]Jframe Contents not Being Displayed

I am trying to display a Loading Image in a new JFrame when the User clicks a particular button in my application.The JFrame is displayed,but it shows nothing!,also with a WHITE background,whereas all the JFrames have a grey default background.What is Wrong here? 当用户单击应用程序中的特定按钮时,我试图在新的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);

        }
    });

Do not put time consuming parts in an event handler or any method running in the event dispatch thread. 不要将耗时的部件放在事件处理程序或事件分发线程中运行的任何方法中。 You may want to use a swing worker instead. 您可能要使用摇摆工人

What is happening is that you are never releasing the UI thread, so your JFrame is never painted. 发生的事情是,您永远不会释放UI线程,因此您的JFrame永远不会被绘制。 Since all graphics operations are done on the UI thread, you must release it, do your calculations, then close the frame if you want the jframe to display anything. 由于所有图形操作都是在UI线程上完成的,因此如果要让jframe显示任何内容,则必须释放它,进行计算,然后关闭该帧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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