Dialogs are a type of Window that pop up over a parent Frame, usually to ask the user to confirm something or display an About box. Dialogs can be modal or non-modal. Modal dialogs monopolise the user’s attention, preventing him from clicking anywhere but in the dialog box. Early versions of Dialog were quite buggy.
JDialog is the Swing equivalent of Dialog.
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 (Graphic User Interface) 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.
available on the web at:
optional Replicator mirror
Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : . If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Your face IP:[220.127.116.11]
|Feedback||You are visitor number 20,719.|