How does JOptionPane works?

hello

I'm trying to make a frame that each time that you open it, it returns a value (like the dialogs in JOptionPane). the problem is that when I do so, using a boolean loop, that exits when the ok button is pressed, then it shows only a blank frame without all its components and so on.

I guess this happen because I call the loop inside the main event thread. I tried look in the JOptionPane code but didn't understand it

[445 byte] By [TheHattera] at [2007-10-2 18:50:44]
# 1
what you need to do is extend a jdialog and make it modal. when a jdialog is set to modal it's call setVissible(true); will block until something calls setvissible false. here is more detail: http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
Ken_Sa at 2007-7-13 20:13:41 > top of Java-index,Desktop,Core GUI APIs...
# 2

In your modal dialog do something like this:

class myDialog extends JDialog{

int result = JOptionPane.CANCEL_OPTION;

public MyDialog(){

setModal (true);

}

private int showDialog(){

setVisible (true);

return result;

}

private void okButtonSelected(){

result = JOptionPane.OK_OPTION;

setVisible(false);

}

private void cancelButtonselected(){

result = JOptionPane.CANCEL_OPTION;

setVisible(false);

}

}

From your frame call showDialog. Your main frame will be blocked at the call to setVisible until something else calls setVisible(false). Then showDialog will return the result.

BaltimoreJohna at 2007-7-13 20:13:41 > top of Java-index,Desktop,Core GUI APIs...