Wait for JFrame dispose
I was wondering it there was a way to pause the execution of code until a frame (say, a popup window) is closed.
NewStudent std =new NewStudent(className);
std.init();
//Something to stop the execution of the below code until the window is disposed
refreshTabs("info");
refreshTabs("tests");
refreshTabs("quizzes");
refreshTabs("hw");
Basically, std.init() opens up the window, then you click finish or cancel (either way, the window is disposed) then I want the code to contine.
I hope this all makes sense. Thanks for the help.
[755 byte] By [
gometro33a] at [2007-10-2 16:35:02]

Check out my ParamDialog class. It is built to do just what you're talking about.
BTW if you need StandardDialog, its parent class and also a useful class in itself search this site
You are welcome to use and modify this code but please do not change the package name or take credit for it as your own work.
ParamDialog.java
==============
package tjacobs.ui;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import tjacobs.CollectionUtils;
import java.awt.*;
import java.util.HashMap;
import java.util.Properties;
/** Usage:
* [code]
* ParamDialog pd = new ParamDialog(new String[] {"A", "B", "C"});
* pd.pack();
* pd.setVisible(true);
* Properties p = pd.getProperties();
*/
public class ParamDialog extends StandardDialog {
public static final String SECRET = "(SECRET)";
String[] fields;
HashMap<String, JTextField> mValues = new HashMap<String, JTextField>();
public ParamDialog(String[] fields) throws HeadlessException {
this(null, fields);
}
public ParamDialog(JFrame owner, String[] fields) {
super(owner);
setModal(true);
this.fields = fields;
JPanel main = new JPanel();
main.setLayout(new GridLayout(fields.length, 1));
for (int i = 0; i < fields.length; i++) {
JPanel con = new JPanel(new FlowLayout());
main.add(con);
JTextField tf;
if (fields[i].endsWith(SECRET)) {
con.add(new JLabel(fields[i].substring(0, fields[i].length() - SECRET.length())));
tf = new JPasswordField();
}
else {
con.add(new JLabel(fields[i]));
tf = new JTextField();
}
tf.setColumns(12);
con.add(tf);
mValues.put(fields[i], tf);
}
this.setMainContent(main);
}
public boolean showApplyButton() {
return false;
}
public void apply() {
}
private boolean mCancel = false;
public void cancel() {
mCancel = true;
super.cancel();
}
public Properties getProperties() {
if (mCancel) return null;
Properties p = new Properties();
for (int i = 0; i < fields.length; i++) {
p.put(fields[i], mValues.get(fields[i]).getText());
}
return p;
}
public static void main (String[] args) {
//ParamDialog pd = new ParamDialog(new String[] {"A", "B", "C"});
//WindowUtilities.visualize(pd);
Properties p = getProperties(new String[] {"A","B","C"});
CollectionUtils.printCollection(p);
}
public static Properties getProperties(String[] fields) {
ParamDialog pd = new ParamDialog(fields);
//pd.setModal(false);
WindowUtilities.visualize(pd);
return pd.getProperties();
}
}