I suspect that the only way of achieving this using the standard modal
property would be to destroy the dialog and then re-establish it with
setModal(false).  This is because setModal is implemented via the dialog's
peer and I don't think that can change.

For an alternative approach see the attached which is an answer I gave to
a similar question on a different e-mail group.

Dave Wathen
Canzonet Limited
http://www.canzonet.com
mailto:[EMAIL PROTECTED] 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Reinstein, Lenny
Sent: 18 March 2002 17:54
To: '[EMAIL PROTECTED]'
Subject: JDialog question.


Can we change the modality of the dialog box at run-time? I.e., if the
dialog is modal but I want to make it not be be modal if a ceratin event
occurs, what can I do? Just calling setModal(false) at run-time does not
seem to have any effect.

Thanks.




_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
--- Begin Message ---
I've achieved this in Swing and I can't think of any reason my
approach wouldn't work for AWT too (in fact it should be easier).
Dialog achieves its modality through its peer (i.e. it makes the
OS do it for it). You can effectively create a modal component 
however by blocking events from reaching any other component 
(other than your panel and its children that is).

I don't have access to the code for this anymore but from memory 
(and as I would expect it to be for AWT) it goes like this:

You need to hook into the AWT event queue: 

    Toolkit.getDefaultToolkit().getSystemEventQueue()
        .push(new MyEventQueue());

MyEventQueue class looks something like:

    class MyEventQueue extends EventQueue {
        Component modal;

        MyEventQueue(Component modal) {
            this.modal = modal;

        protected void dispatchEvent(AWTEvent event) {
            if (isForModal((Component) event.getSource()) {
                super.dispatchEvent(event);

            } else {
                event.consume();
            }
        }

        private boolean isForModal(Component component) {
            boolean result = modal.equals(component);

            if (!result && component != null) {
                result = isForModal(component.getParent());
            }
        }
    } 
    
In Swing you have to do extra work to determine the lightweight
JComponent to which the event will resolve and you have to keep
track of mouse drags outside the JComponent (e.g. scroll bars
continue to scroll even if the mouse pointer leaves the confines
of the modal components).  But for AWT the OS should do all that
for you.

What you may have a problem with is focus events but try this out
and see what happens first.

Dave Wathen
Canzonet Limited
http://www.canzonet.com
mailto:[EMAIL PROTECTED] 

-----Original Message-----
From: Moderated discussion of advanced Java topics.
[mailto:[EMAIL PROTECTED]]On Behalf Of Victor Grazi
Sent: 15 March 2002 01:22
To: [EMAIL PROTECTED]
Subject: [ADVANCED-JAVA] How o get a blocking dialog


I would like to write an awt component that acts like a Y/N modal Dialog,
but extends Panel instead of Window.

The idea is that a program should show the dialog, then block until the
dialog is hidden.

My first thought was to put a wait() in the dialog's setVisible(true) and a
notify in the button listeners. However, since the current thread is
launched from the main dispatch thread, the program locks up when the wait
is called.

I was hoping I could go into the awt Dialog source and copy some code from
there, but some of those methods are package protected so I can't get to
them

Any advice?

Thanks/Victor

You can read messages from the ADVANCED-JAVA archive, unsubscribe, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
--- End Message ---

Reply via email to