0

I'm trying to open a new window when I click on a button. In this new window there is a form. The form contains information which is used to create a JScrollPane in the first window. I'd like to create the JScrollPane when the user completes all the element in the form. I tried with Thread but this does not work.

This is my code :

f(e.getSource() == menuAjoutern){
        JScrollPane scrollpane;
        nomniveaux++;

        Frame p = new Frame();
        p.setContentPane(new PanelInfoCrea());
        p.setVisible(true);

        /*Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                Frame p = new Frame();
                p.setContentPane(new PanelInfoCrea());
                p.setVisible(true);

            }
        });
        t.start();


        Frame.creation = true;
        while(Frame.creation) {
            try {
                System.out.println("oui");
                Thread.sleep(1);
            } catch (InterruptedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }*/
        scrollpane = new JScrollPane(Frame.p.getListeNiveau().get(Frame.p.getListeNiveau().size()-1).dessinerPlateauCreation(this.getWidth(), this.getHeight(), hauteur));
        pane.add("niveau "+nomniveaux ,scrollpane);
    }

Here I try to wait that boolean is false for create the JScrollPane. The boolean change state when second window is close. Do you have any ideas?

T-Heron
  • 5,385
  • 7
  • 26
  • 52
Sebastien
  • 7
  • 5
  • 2
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Mar 15 '17 at 13:15
  • 1
    [Some similar questions](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:stackoverflow.com+java+swing+wait+for+jframe+to+close&*). I also posted a community wiki answer before I found the duplicates. – Hovercraft Full Of Eels Mar 15 '17 at 13:16

1 Answers1

1

The 2nd window should be a modal JDialog or a JOptionPane (which actually is a modal dialog). This way the calling code will halt when the 2nd window has been displayed and won't resume until the 2nd window is no longer visible.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373