nikel
nikel

Reputation: 3564

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);

        }
    });

Upvotes: 1

Views: 778

Answers (2)

ControlAltDel
ControlAltDel

Reputation: 35051

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.

Upvotes: 1

Howard
Howard

Reputation: 39197

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.

Upvotes: 4

Related Questions