JDialog is the Swing equivalent of Dialog.
| Gotchas | Learning More |
| Sample Code | Links |
Dialog constructors want a Frame as parent. Unfortunately, Applets are effectively Panels, not Frames. To embed a Dialog in an Applet, you must chase the Component. getParent chain until you find an instanceof Frame. Alternatively, you can pop up a new Frame for the Dialog to live in.
Modal Dialogs are most peculiar. They don’t immediately return to the caller when you call setVisible( true) followed by a return. They only return after the Dialog has disposed. Check out ColorChooser in FontShowerAwt for how you pass data gleaned from the user back to the code that invoked the Dialog.
In a nutshell, you first construct the modal Dialog, but don’t call setVisible( true ). Then you call a Dialog. query method that calls setVisible( true ) then returns the desired variables. Setvisible( true ) magically puts the query method on ice while the user interacts and finally hits OK or Cancel which triggers an ActionListener to call dispose. At that point the query method magically resumes executing, and can pick out whatever data it wants that the GUI interactions put into the Dialog fields. It can then bundle them into an Object or array to return to the caller.
If Dialogs fail to paint anything, it could be because you forgot to do a setSize, validate(), or setVisible( true ). Dialog.setBackground does not work.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.58] | |||
| You are visitor number 15,564. | |||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/jgloss/dialog.html | J:\mindprod\jgloss\dialog.html | ||