简体   繁体   中英

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?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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