Hi everyone,
I am currently writing an application that works as a base plugin
environment for a variety of "other" applications. Each of the "other"
applications or 'Plugins' are loaded in a new tab (in aJPanel) on the
main Tab pane when the user so wishes. The tabpane is added as a
component to a JFrame (which is my main frame).
My problem is that many of the Plugins popup modal dialog windows of
their own during runtime and I do NOT want the modality of the dialog
windows opened by Plugins to block my main application (the main frame
or the tabpane).
I do want the specific panel on the tabpane that displays the Plugin to
be blocked but not the rest of the GUI. This means that the user can
move from one tab to another even when one of the tabs has its own
modal dialog window open.
Currently I have some code added to my main frame that sets its
windowlistener to listen for times when the main frame is deactivated
and when it finds that a JDialog caused the deactivation it tries to
make that Dialog non-modal, unfortunately it does not work :(
Here is the code mentioned above:
public void windowDeactivated(WindowEvent e) {
super.windowDeactivated(e);
Window wFrame = e.getWindow();
Window wDialog = e.getOppositeWindow();
if (wDialog != null) {
JDialog d1;
try {
d1 = (JDialog) wDialog;
} catch (Exception ex) {
return;
}
if (d1.isModal()) {
d1.setModal(false);
Graphics g = d1.getGraphics();
if (g != null) {
d1.update(g);
}
// Tried everything here
//d1.validate();
d1.repaint();
d1.show();
d1.setVisible(true);
// Tried everything here
// wDialog.setVisible(false);
//wDialog.setEnabled(false);
//JDialog d = new JDialog(mainFrame, false);
//for (int i = 0; i < wDialog.getComponentCount(); i++) {
// Component c = wDialog.getComponent(i); d.add(c);
// d.setSize(c.getWidth(), c.getHeight() + 20); }
// d.setResizable(false);
// d.setDefaultCloseOperation(JDialog.
DISPOSE_ON_CLOSE);
// d.setVisible(true); d.show(); // wDialog.dispose();
//}
}
}
}
Does anyone know a good way for me to handle this within the plugin
based application itself, so that the plugin applications are allowed
to create modal dialogs but I "catch" these modal dialogs and only make
them semi-modal (I know of a solution to make things semi-modal but not
how to catch the dialogs and un-modal them).
Vyacheslav Baranov - 22 Feb 2006 18:45 GMT
Hi,
Few comments regarding your code:
1. Modality of the dialog can only be changed while dialog is hidden.
If you change it while the dialog is showing, it will have effect only
after hiding and showing the dialog. (see Dialog.setModal() specs)
2. Trying to cast to a JDialog is a bad idea :)
You can simply write:
if (!(wDialog instanceof JDialog)) {
return;
}
3. If it's applicable you can use mustang's modality features
(see specs of Dialog.setModalityType() for details)
4. If previous is not applicable you can implement some kind
of modal dialogs showing internal frames on MODAL_LAYER of
JLayeredPane.
> Hi everyone,
>
[quoted text clipped - 72 lines]
> them semi-modal (I know of a solution to make things semi-modal but not
> how to catch the dialogs and un-modal them).
Andrey Kuznetsov - 26 Feb 2006 10:17 GMT
> I am currently writing an application that works as a base plugin
> environment for a variety of "other" applications. Each of the "other"
> applications or 'Plugins' are loaded in a new tab (in aJPanel) on the
> main Tab pane when the user so wishes. The tabpane is added as a
> component to a JFrame (which is my main frame).
See this tip about semimodal dialogs:
http://www.javaworld.com/www.javaworld.com/javatips/jw-javatip89_p.html

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities