I am trying to use a `JDialog` as input for a `String`. But the text I get is from before I click the Button.

this is my dialog:

```
public class AddMemberDialog extends JDialog {

    private JTextField name;

    public AddMemberDialog() {
        super(new JFrame("Add Member"), "Add Member");
        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        this.setMinimumSize(new Dimension(500, 500));
        this.name = new JTextField();

        JButton add = new JButton("Add");
        add.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {
                close();            
            }
        });
        this.setLayout(new GridLayout(2, 1, 5, 5));

        this.add(name);
        this.add(add);
        this.pack();
    }

    private void close(){   this.dispose(); }

    public String getName(){    return this.name.getText(); }
}

```

and here is what I am using to get to `String`:

```
AddMemberDialog input = new AddMemberDialog();
input.setLocationRelativeTo(this);
input.setVisible(true);
String txt = input.getName();

```