0

I have first frame containing a button. On pressing the button I invoke actionPerformed() method of different class.

JButton compress = new JButton("Submit");
compress.addActionListener(new Action1(inp,out,frame1)); // inp,out are textboxes and frame1 is 1st frame containing textboxes and JButton

In actionPerformed() of class Action1. I have created another frame there as follows

static class Action1 implements ActionListener {        

        JTextField input_path,out_path;
        JFrame prev;

        public Action1(JTextField inp,JTextField out,JFrame jf)
        {
            input_path = inp;
            out_path = out;
            prev = jf;
        }

        public void actionPerformed (ActionEvent e) {           
            prev.dispose();
            try{
                drawFrame();
                // launch the compression job
                launchJob(input_path.getText(),out_path.getText());
            }
            catch(IOException io){
                io.printStackTrace();
            }

        }
        public void drawFrame()
        {
            JFrame frame2 = new JFrame("New Frame");
            JPanel panel = new JPanel();

            frame2.setSize(400,300);
            frame2.setLocation(500, 300);
            JLabel label = new JLabel(" in Progress...");

            panel.add(label);
            frame2.add(panel);
            frame2.setVisible(true);
        }
    }

But in actionPerformed(), the contents of the frame2 are getting visible after method launchJob() is executed. I want to display(make visible) content of frame2 before my function launchJob() starts executing. Can you plz suggest where im going wrong or some alternative. Thank you.

Sumit
  • 27
  • 8

1 Answers1

0

I have just verified that your frame is being set visible before your method launchJob() is called.

Consider adding some print statements to debug, for example, at the end of the drawFrame() method , add the following code:

frame2.setVisible(true);
System.out.println("frame visible");

Do the same at the start of the launch job method:

System.out.println("doing launch job");

You will see that the output is:

frame visible
doing launch job

This verifies that the JFrame is in fact being made visible before your launch job method.

Zain
  • 469
  • 3
  • 9
  • JFrame is getting visible but the content(panel ,label "in progress") of Jframe is visible after the launchJob() method has completed...can u tell me abt that plz... – Sumit May 17 '16 at 14:03
  • For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson May 18 '16 at 03:38
  • @Sumit: see [here](http://stackoverflow.com/q/20901770/2711488), especially the answers to point 4. – Holger May 18 '16 at 12:30