I have a swing application that has many frames and dialogs. Is it possible to make a dialog modal for some frames and non-modal for the others frames?
I have a swing application that has many frames and
dialogs. Is it possible to make a dialog modal for
some frames and non-modal for the others frames?
Thanks.
Its quite easy
first create your dialog
class Error_Dialog extends JDialog
//standard error dialog for displaying error messages
{
etc etc etc
}
ok then use code like this in your frame for a modal dialog
Thanks, but my problem is that I need to display the
frames at same time.
i'm not sure i understand what you mean...
dialogs may hide underlying frames if you press alt+tab while a dialog has focus, but this occurs only if you created the dialog without a reference to the underlying (owner) frame (or dialog). if your dialog is created like this:
JDialog dialog = new JDialog(owner) ,
where "owner" is a JFrame or JDialog, then alt+tab will work fine.
Thanks, but my problem is that I need to display the
frames at same time.
You can only make one frame modal, AFAIK (in any language I've known). If you need two modal frames, can you possibly combine their GUIs onto one frame?
You could launch your non-modal dialog in a separate thread. Code your dialog as a separate class and launch it with a SwingWorker.
I just finished an Open-Source application that does this, "BabyTalk Web", a SWING desktop text-to-speech that uses JAXB and Java Web Services. Check out how DialogList is launched.
http://www.quadmore.com/babytalkweb/
Hope this helps,
Bert Szoghy
Quadmore Software Services
"Home of Java Rollout for Windows"