FileDocCategorySizeDatePackage
Dialog.javaAPI DocJava SE 6 API64622Tue Jun 10 00:25:14 BST 2008java.awt

Dialog

public class Dialog extends Window
A Dialog is a top-level window with a title and a border that is typically used to take some form of input from the user. The size of the dialog includes any area designated for the border. The dimensions of the border area can be obtained using the getInsets method, however, since these dimensions are platform-dependent, a valid insets value cannot be obtained until the dialog is made displayable by either calling pack or show. Since the border area is included in the overall size of the dialog, the border effectively obscures a portion of the dialog, constraining the area available for rendering and/or displaying subcomponents to the rectangle which has an upper-left corner location of (insets.left, insets.top), and has a size of width - (insets.left + insets.right) by height - (insets.top + insets.bottom).

The default layout for a dialog is BorderLayout.

A dialog may have its native decorations (i.e. Frame & Titlebar) turned off with setUndecorated. This can only be done while the dialog is not {@link Component#isDisplayable() displayable}.

A dialog may have another window as its owner when it's constructed. When the owner window of a visible dialog is minimized, the dialog will automatically be hidden from the user. When the owner window is subsequently restored, the dialog is made visible to the user again.

In a multi-screen environment, you can create a Dialog on a different screen device than its owner. See {@link java.awt.Frame} for more information.

A dialog can be either modeless (the default) or modal. A modal dialog is one which blocks input to some other top-level windows in the application, except for any windows created with the dialog as their owner. See AWT Modality specification for details.

Dialogs are capable of generating the following WindowEvents: WindowOpened, WindowClosing, WindowClosed, WindowActivated, WindowDeactivated, WindowGainedFocus, WindowLostFocus.

see
WindowEvent
see
Window#addWindowListener
version
1.127, 06/19/07
author
Sami Shaio
author
Arthur van Hoff
since
JDK1.0

Fields Summary
boolean
resizable
A dialog's resizable property. Will be true if the Dialog is to be resizable, otherwise it will be false.
boolean
undecorated
This field indicates whether the dialog is undecorated. This property can only be changed while the dialog is not displayable. undecorated will be true if the dialog is undecorated, otherwise it will be false.
public static final ModalityType
DEFAULT_MODALITY_TYPE
Default modality type for modal dialogs. The default modality type is APPLICATION_MODAL. Calling the oldstyle setModal(true) is equal to setModalityType(DEFAULT_MODALITY_TYPE).
boolean
modal
True if this dialog is modal, false is the dialog is modeless. A modal dialog blocks user input to some application top-level windows. This field is kept only for backwards compatibility. Use the {@link Dialog.ModalityType ModalityType} enum instead.
ModalityType
modalityType
Modality type of this dialog. If the dialog's modality type is not {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all user input to some application top-level windows.
private static final ModalExclusionType
DEFAULT_MODAL_EXCLUSION_TYPE
static transient IdentityArrayList
modalDialogs
transient IdentityArrayList
blockedWindows
String
title
Specifies the title of the Dialog. This field can be null.
private transient boolean
keepBlocking
private transient ModalEventFilter
modalFilter
volatile transient boolean
isInHide
volatile transient boolean
isInDispose
private static final String
base
private static int
nameCounter
private static final long
serialVersionUID
private transient AppContext
showAppContext
Stores the app context on which event dispatch thread the dialog is being shown. Initialized in show(), used in hideAndDisposeHandler()
Constructors Summary
public Dialog(Frame owner)
Constructs an initially invisible, modeless Dialog with the specified owner Frame and an empty title.

param
owner the owner of the dialog or null if this dialog has no owner
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
see
Component#setSize
see
Component#setVisible


                                                                         
        
         this(owner, "", false);
     
public Dialog(Window owner)
Constructs an initially invisible, modeless Dialog with the specified owner Window and an empty title.

param
owner the owner of the dialog. The owner must be an instance of {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any of their descendents or null
exception
java.lang.IllegalArgumentException if the owner is not an instance of {@link java.awt.Dialog Dialog} or {@link java.awt.Frame Frame}
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
since
1.6

        this(owner, null, ModalityType.MODELESS);
    
public Dialog(Window owner, String title)
Constructs an initially invisible, modeless Dialog with the specified owner Window and title.

param
owner the owner of the dialog. The owner must be an instance of {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any of their descendents or null
param
title the title of the dialog or null if this dialog has no title
exception
java.lang.IllegalArgumentException if the owner is not an instance of {@link java.awt.Dialog Dialog} or {@link java.awt.Frame Frame}
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
since
1.6

        this(owner, title, ModalityType.MODELESS);
    
public Dialog(Window owner, ModalityType modalityType)
Constructs an initially invisible Dialog with the specified owner Window and modality and an empty title.

param
owner the owner of the dialog. The owner must be an instance of {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any of their descendents or null
param
modalityType specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
exception
java.lang.IllegalArgumentException if the owner is not an instance of {@link java.awt.Dialog Dialog} or {@link java.awt.Frame Frame}
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
exception
SecurityException if the calling thread does not have permission to create modal dialogs with the given modalityType
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
java.awt.Toolkit#isModalityTypeSupported
since
1.6

        this(owner, null, modalityType);
    
public Dialog(Window owner, String title, ModalityType modalityType)
Constructs an initially invisible Dialog with the specified owner Window, title and modality.

param
owner the owner of the dialog. The owner must be an instance of {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any of their descendents or null
param
title the title of the dialog or null if this dialog has no title
param
modalityType specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
exception
java.lang.IllegalArgumentException if the owner is not an instance of {@link java.awt.Dialog Dialog} or {@link java.awt.Frame Frame}
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
exception
SecurityException if the calling thread does not have permission to create modal dialogs with the given modalityType
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
java.awt.Toolkit#isModalityTypeSupported
since
1.6

        super(owner);

        if ((owner != null) &&
            !(owner instanceof Frame) &&
            !(owner instanceof Dialog))
        {
            throw new IllegalArgumentException("Wrong parent window");
        }

        this.title = title;
        setModalityType(modalityType);
        SunToolkit.checkAndSetPolicy(this, false);
    
public Dialog(Window owner, String title, ModalityType modalityType, GraphicsConfiguration gc)
Constructs an initially invisible Dialog with the specified owner Window, title, modality and GraphicsConfiguration.

param
owner the owner of the dialog. The owner must be an instance of {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any of their descendents or null
param
title the title of the dialog or null if this dialog has no title
param
modalityType specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
param
gc the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
exception
java.lang.IllegalArgumentException if the owner is not an instance of {@link java.awt.Dialog Dialog} or {@link java.awt.Frame Frame}
exception
java.lang.IllegalArgumentException if gc is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
exception
SecurityException if the calling thread does not have permission to create modal dialogs with the given modalityType
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
java.awt.Toolkit#isModalityTypeSupported
since
1.6

        super(owner, gc);

        if ((owner != null) &&
            !(owner instanceof Frame) &&
            !(owner instanceof Dialog))
        {
            throw new IllegalArgumentException("wrong owner window");
        }

        this.title = title;
        setModalityType(modalityType);
        SunToolkit.checkAndSetPolicy(this, false);
    
public Dialog(Frame owner, boolean modal)
Constructs an initially invisible Dialog with the specified owner Frame and modality and an empty title.

param
owner the owner of the dialog or null if this dialog has no owner
param
modal specifes whether dialog blocks user input to other top-level windows when shown. If false, the dialog is MODELESS; if true, the modality type property is set to DEFAULT_MODALITY_TYPE
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless

         this(owner, "", modal);
     
public Dialog(Frame owner, String title)
Constructs an initially invisible, modeless Dialog with the specified owner Frame and title.

param
owner the owner of the dialog or null if this dialog has no owner
param
title the title of the dialog or null if this dialog has no title
exception
IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
see
Component#setSize
see
Component#setVisible

         this(owner, title, false);
     
public Dialog(Frame owner, String title, boolean modal)
Constructs an initially invisible Dialog with the specified owner Frame, title and modality.

param
owner the owner of the dialog or null if this dialog has no owner
param
title the title of the dialog or null if this dialog has no title
param
modal specifes whether dialog blocks user input to other top-level windows when shown. If false, the dialog is MODELESS; if true, the modality type property is set to DEFAULT_MODALITY_TYPE
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
Component#setSize
see
Component#setVisible

         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
     
public Dialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)
Constructs an initially invisible Dialog with the specified owner Frame, title, modality, and GraphicsConfiguration.

param
owner the owner of the dialog or null if this dialog has no owner
param
title the title of the dialog or null if this dialog has no title
param
modal specifes whether dialog blocks user input to other top-level windows when shown. If false, the dialog is MODELESS; if true, the modality type property is set to DEFAULT_MODALITY_TYPE
param
gc the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
exception
java.lang.IllegalArgumentException if gc is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
Component#setSize
see
Component#setVisible
since
1.4

         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
     
public Dialog(Dialog owner)
Constructs an initially invisible, modeless Dialog with the specified owner Dialog and an empty title.

param
owner the owner of the dialog or null if this dialog has no owner
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
since
1.2

         this(owner, "", false);
     
public Dialog(Dialog owner, String title)
Constructs an initially invisible, modeless Dialog with the specified owner Dialog and title.

param
owner the owner of the dialog or null if this has no owner
param
title the title of the dialog or null if this dialog has no title
exception
java.lang.IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
since
1.2

         this(owner, title, false);
     
public Dialog(Dialog owner, String title, boolean modal)
Constructs an initially invisible Dialog with the specified owner Dialog, title, and modality.

param
owner the owner of the dialog or null if this dialog has no owner
param
title the title of the dialog or null if this dialog has no title
param
modal specifes whether dialog blocks user input to other top-level windows when shown. If false, the dialog is MODELESS; if true, the modality type property is set to DEFAULT_MODALITY_TYPE
exception
IllegalArgumentException if the owner's GraphicsConfiguration is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
since
1.2

         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
     
public Dialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc)
Constructs an initially invisible Dialog with the specified owner Dialog, title, modality and GraphicsConfiguration.

param
owner the owner of the dialog or null if this dialog has no owner
param
title the title of the dialog or null if this dialog has no title
param
modal specifes whether dialog blocks user input to other top-level windows when shown. If false, the dialog is MODELESS; if true, the modality type property is set to DEFAULT_MODALITY_TYPE
param
gc the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
exception
java.lang.IllegalArgumentException if gc is not from a screen device
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
Component#setSize
see
Component#setVisible
since
1.4

         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
     
Methods Summary
public voidaddNotify()
Makes this Dialog displayable by connecting it to a native screen resource. Making a dialog displayable will cause any of its children to be made displayable. This method is called internally by the toolkit and should not be called directly by programs.

see
Component#isDisplayable
see
#removeNotify

	synchronized (getTreeLock()) {
	    if (parent != null && parent.getPeer() == null) {
                parent.addNotify();
	    }

	    if (peer == null) {
	        peer = getToolkit().createDialog(this);
	    }
	    super.addNotify();
	}
    
voidblockWindow(java.awt.Window w)

        if (!w.isModalBlocked()) {
            w.setModalBlocked(this, true);
            blockedWindows.add(w);
        }
    
static voidcheckShouldBeBlocked(java.awt.Window w)

        synchronized (w.getTreeLock()) {
            for (int i = 0; i < modalDialogs.size(); i++) {
                Dialog modalDialog = modalDialogs.get(i);
                if (modalDialog.shouldBlock(w)) {
                    modalDialog.blockWindow(w);
                    break;
                }
            }
        }
    
private booleanconditionalShow(java.awt.Component toFocus, java.util.concurrent.atomic.AtomicLong time)

return
true if we actually showed, false if we just called toFront()

        boolean retval;

        synchronized (getTreeLock()) {
            if (peer == null) {
                addNotify();
            }
            validate();
            if (visible) {
                toFront();
                retval = false;
            } else {
                visible = retval = true;

                // check if this dialog should be modal blocked BEFORE calling peer.show(),
                // otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly
                // generated for the dialog
                if (!isModal()) {
                    checkShouldBeBlocked(this);
                } else {
                    modalShow();
                }

                if (toFocus != null && time != null && isFocusable() && 
                    isEnabled() && !isModalBlocked()) {
                    // keep the KeyEvents from being dispatched
                    // until the focus has been transfered
                    time.set(Toolkit.getEventQueue().getMostRecentEventTimeEx());
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        enqueueKeyEvents(time.get(), toFocus);
                }

                peer.show(); // now guaranteed never to block
                if (isModalBlocked()) {
                    modalBlocker.toFront();
                }

                setLocationByPlatform(false);
                for (int i = 0; i < ownedWindowList.size(); i++) {
                    Window child = ownedWindowList.elementAt(i).get();
                    if ((child != null) && child.showWithParent) {
                        child.show();
                        child.showWithParent = false;
                    }       // endif
                }   // endfor
                Window.updateChildFocusableWindowState(this);

                createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
                                      this, parent,
                                      HierarchyEvent.SHOWING_CHANGED,
                                      Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
                if (componentListener != null ||
                        (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
                        Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
                    ComponentEvent e =
                        new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
                    Toolkit.getEventQueue().postEvent(e);
                }
            }
        }

        if (retval && (state & OPENED) == 0) {
            postWindowEvent(WindowEvent.WINDOW_OPENED);
            state |= OPENED;
        }

        return retval;
    
java.lang.StringconstructComponentName()
Construct a name for this component. Called by getName() when the name is null.

        synchronized (getClass()) {
	    return base + nameCounter++;
	}
    
voiddoDispose()
Disposes the Dialog and then causes show() to return if it is currently blocked.

        // fix for 5048370: set isInDispose flag to true to prevent calling
        // to hideAndDisposeHandler() from hide()
        isInDispose = true;
        super.doDispose();
        hideAndDisposeHandler();
        isInDispose = false;
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Dialog. For dialogs, the AccessibleContext takes the form of an AccessibleAWTDialog. A new AccessibleAWTDialog instance is created if necessary.

return
an AccessibleAWTDialog that serves as the AccessibleContext of this Dialog
since
1.3

        if (accessibleContext == null) {
            accessibleContext = new AccessibleAWTDialog();
        }
        return accessibleContext;
    
public java.awt.Dialog$ModalityTypegetModalityType()
Returns the modality type of this dialog.

return
modality type of this dialog
see
java.awt.Dialog#setModalityType
since
1.6

        return modalityType;
    
public java.lang.StringgetTitle()
Gets the title of the dialog. The title is displayed in the dialog's border.

return
the title of this dialog window. The title may be null.
see
java.awt.Dialog#setTitle

	return title;
    
public voidhide()
Hides the Dialog and then causes {@code show} to return if it is currently blocked.

see
Window#show
see
Window#dispose
see
Window#setVisible(boolean)
deprecated
As of JDK version 1.5, replaced by {@link #setVisible(boolean) setVisible(boolean)}.

        hideAndDisposePreHandler();
        super.hide();
        // fix for 5048370: if hide() is called from super.doDispose(), then
        // hideAndDisposeHandler() should not be called here as it will be called
        // at the end of doDispose()
        if (!isInDispose) {
            hideAndDisposeHandler();
        }
    
private voidhideAndDisposeHandler()

        if (keepBlocking) {
            synchronized (getTreeLock()) {
                keepBlocking = false;

                if (showAppContext != null) {
                    // Wake up event dispatch thread on which the dialog was
                    // initially shown
                    SunToolkit.postEvent(showAppContext,
                                         new PeerEvent(this,
                                                       new WakingRunnable(),
                                                       PeerEvent.PRIORITY_EVENT));
                    showAppContext = null;
                }
                EventQueue.invokeLater(new WakingRunnable());
                getTreeLock().notifyAll();
            }
        }
        isInHide = false;
    
private voidhideAndDisposePreHandler()

        isInHide = true;
        if (keepBlocking) {
            synchronized (getTreeLock()) {
                if (modalDialogs.contains(this)) {
                    modalHide();
                    // dialog can be shown and the disposed before its
                    // modal filter is created
                    if (modalFilter != null) {
                        modalFilter.disable();
                    }
                }
            }
        }
    
private static native voidinitIDs()
Initialize JNI field and method IDs

voidinterruptBlocking()

        if (isModal()) {
            disposeImpl();
        } else if (windowClosingException != null) {
            windowClosingException.fillInStackTrace();
            windowClosingException.printStackTrace();
            windowClosingException = null;
        }
    
public booleanisModal()
Indicates whether the dialog is modal.

This method is obsolete and is kept for backwards compatiblity only. Use {@link #getModalityType getModalityType()} instead.

return
true if this dialog window is modal; false otherwise
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#setModal
see
java.awt.Dialog#getModalityType
see
java.awt.Dialog#setModalityType

        return isModal_NoClientCode();
    
final booleanisModal_NoClientCode()

        return modalityType != ModalityType.MODELESS;
    
public booleanisResizable()
Indicates whether this dialog is resizable by the user. By default, all dialogs are initially resizable.

return
true if the user can resize the dialog; false otherwise.
see
java.awt.Dialog#setResizable

	return resizable;
    
public booleanisUndecorated()
Indicates whether this dialog is undecorated. By default, all dialogs are initially decorated.

return
true if dialog is undecorated; false otherwise.
see
java.awt.Dialog#setUndecorated
since
1.4

	return undecorated;
    
voidmodalHide()

        modalDialogs.remove(this);
        // we should unblock all the windows first...
        IdentityArrayList<Window> save = new IdentityArrayList<Window>();
        int blockedWindowsCount = blockedWindows.size();
        for (int i = 0; i < blockedWindowsCount; i++) {
            Window w = blockedWindows.get(0);
            save.add(w);
            unblockWindow(w); // also removes w from blockedWindows
        }
        // ... and only after that check if they should be blocked
        // by another dialogs
        for (int i = 0; i < blockedWindowsCount; i++) {
            Window w = save.get(i);
            if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {
                Dialog d = (Dialog)w;
                d.modalShow();
            } else {
                checkShouldBeBlocked(w);
            }
        }
    
voidmodalShow()

        modalDialogs.add(this);

        // find all the dialogs that block this one
        IdentityArrayList<Dialog> blockers = new IdentityArrayList<Dialog>();
        for (Dialog d : modalDialogs) {
            if (d.shouldBlock(this)) {
                Window w = d;
                while ((w != null) && (w != this)) {
                    w = (Window)(w.getOwner_NoClientCode());
                }
                if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) {
                    blockers.add(d);
                }
            }
        }

        // add all blockers' blockers to blockers :)
        for (int i = 0; i < blockers.size(); i++) {
            Dialog blocker = blockers.get(i);
            if (blocker.isModalBlocked()) {
                Dialog blockerBlocker = blocker.getModalBlocker();
                if (!blockers.contains(blockerBlocker)) {
                    blockers.add(i + 1, blockerBlocker);
                }
            }
        }

        if (blockers.size() > 0) {
            blockers.get(0).blockWindow(this);
        }

        // find all windows from blockers' hierarchies
        IdentityArrayList<Window> blockersHierarchies = new IdentityArrayList<Window>(blockers);
        int k = 0;
        while (k < blockersHierarchies.size()) {
            Window w = blockersHierarchies.get(k);
            Window[] ownedWindows = w.getOwnedWindows_NoClientCode();
            for (Window win : ownedWindows) {
                blockersHierarchies.add(win);
            }
            k++;
        }

        // block all windows from scope of blocking except from blockers' hierarchies
        IdentityArrayList<Window> unblockedWindows = Window.getAllUnblockedWindows();
        for (Window w : unblockedWindows) {
            if (shouldBlock(w) && !blockersHierarchies.contains(w)) {
                if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {
                    Dialog wd = (Dialog)w;
                    if (wd.shouldBlock(this) && (modalDialogs.indexOf(wd) > modalDialogs.indexOf(this))) {
                        continue;
                    }
                }
                blockWindow(w);
            }
        }

        if (!isModalBlocked()) {
            updateChildrenBlocking();
        }
    
final voidmodalityPopped()

        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            SunToolkit stk = (SunToolkit)tk;
            stk.notifyModalityPopped(this);
        }
    
final voidmodalityPushed()

        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            SunToolkit stk = (SunToolkit)tk;
            stk.notifyModalityPushed(this);
        }
    
protected java.lang.StringparamString()
Returns a string representing the state of this dialog. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

return
the parameter string of this dialog window.

        String str = super.paramString() + "," + modalityType;
        if (title != null) {
            str += ",title=" + title;
        }
        return str;
    
private voidreadObject(java.io.ObjectInputStream s)

        GraphicsEnvironment.checkHeadless();
        s.defaultReadObject();

        // in 1.5 or earlier modalityType was absent, so use "modal" instead
        if (modalityType == null) {
            setModal(modal);
        }

        blockedWindows = new IdentityArrayList();
    
public voidsetModal(boolean modal)
Specifies whether this dialog should be modal.

This method is obsolete and is kept for backwards compatibility only. Use {@link #setModalityType setModalityType()} instead.

Note: changing modality of the visible dialog may have no effect until it is hidden and then shown again.

param
modal specifies whether dialog blocks input to other windows when shown; calling to setModal(true) is equivalent to setModalityType(Dialog.DEFAULT_MODALITY_TYPE), and calling to setModal(false) is equvivalent to setModalityType(Dialog.ModalityType.MODELESS)
see
java.awt.Dialog#DEFAULT_MODALITY_TYPE
see
java.awt.Dialog.ModalityType#MODELESS
see
java.awt.Dialog#isModal
see
java.awt.Dialog#getModalityType
see
java.awt.Dialog#setModalityType
since
1.1

        this.modal = modal;
        setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
    
public voidsetModalityType(java.awt.Dialog$ModalityType type)
Sets the modality type for this dialog. See {@link java.awt.Dialog.ModalityType ModalityType} for possible modality types.

If the given modality type is not supported, MODELESS is used. You may want to call getModalityType() after calling this method to ensure that the modality type has been set.

Note: changing modality of the visible dialog may have no effect until it is hidden and then shown again.

param
type specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
exception
SecurityException if the calling thread does not have permission to create modal dialogs with the given modalityType
see
java.awt.Dialog#getModalityType
see
java.awt.Toolkit#isModalityTypeSupported
since
1.6

        if (type == null) {
            type = Dialog.ModalityType.MODELESS;
        }
        if (modalityType == type) {
            return;
        }
        if (type == ModalityType.TOOLKIT_MODAL) {
            SecurityManager sm = System.getSecurityManager();
            if (sm != null) {
                sm.checkPermission(SecurityConstants.TOOLKIT_MODALITY_PERMISSION);
            }
        }
        modalityType = type;
        modal = (modalityType != ModalityType.MODELESS);
    
public voidsetResizable(boolean resizable)
Sets whether this dialog is resizable by the user.

param
resizable true if the user can resize this dialog; false otherwise.
see
java.awt.Dialog#isResizable

        boolean testvalid = false;

        synchronized (this) {
            this.resizable = resizable;
            DialogPeer peer = (DialogPeer)this.peer;
            if (peer != null) {
                peer.setResizable(resizable);
                testvalid = true;
            }
        }

        // On some platforms, changing the resizable state affects
        // the insets of the Dialog. If we could, we'd call invalidate()
        // from the peer, but we need to guarantee that we're not holding
        // the Dialog lock when we call invalidate().
        if (testvalid && valid) {
            invalidate();
        }
    
public voidsetTitle(java.lang.String title)
Sets the title of the Dialog.

param
title the title displayed in the dialog's border; a null value results in an empty title
see
#getTitle

        String oldTitle = this.title;

        synchronized(this) {
            this.title = title;
            DialogPeer peer = (DialogPeer)this.peer;
            if (peer != null) {
                peer.setTitle(title);
            }
        }
        firePropertyChange("title", oldTitle, title);
    
public voidsetUndecorated(boolean undecorated)
Disables or enables decorations for this dialog. This method can only be called while the dialog is not displayable.

param
undecorated true if no dialog decorations are to be enabled; false if dialog decorations are to be enabled.
throws
IllegalComponentStateException if the dialog is displayable.
see
#isUndecorated
see
Component#isDisplayable
since
1.4

        /* Make sure we don't run in the middle of peer creation.*/
        synchronized (getTreeLock()) {
            if (isDisplayable()) {
                throw new IllegalComponentStateException("The dialog is displayable.");
            }
            this.undecorated = undecorated;
        }
    
public voidsetVisible(boolean b)
Shows or hides this {@code Dialog} depending on the value of parameter {@code b}.

param
b if {@code true}, makes the {@code Dialog} visible, otherwise hides the {@code Dialog}. If the dialog and/or its owner are not yet displayable, both are made displayable. The dialog will be validated prior to being made visible. If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)} to return if it is currently blocked.

Notes for modal dialogs.

  • {@code setVisible(true)}: If the dialog is not already visible, this call will not return until the dialog is hidden by calling {@code setVisible(false)} or {@code dispose}.
  • {@code setVisible(false)}: Hides the dialog and then returns on {@code setVisible(true)} if it is currently blocked.
  • It is OK to call this method from the event dispatching thread because the toolkit ensures that other events are not blocked while this method is blocked.
see
java.awt.Window#setVisible
see
java.awt.Window#dispose
see
java.awt.Component#isDisplayable
see
java.awt.Component#validate
see
java.awt.Dialog#isModal

        super.setVisible(b);
    
booleanshouldBlock(java.awt.Window w)

        if (!isVisible_NoClientCode() ||
            (!w.isVisible_NoClientCode() && !w.isInShow) ||
            isInHide ||
            (w == this) ||
            !isModal_NoClientCode())
        {
            return false;
        }
        if ((w instanceof Dialog) && ((Dialog)w).isInHide) {
            return false;
        }
        // check if w is from children hierarchy
        // fix for 6271546: we should also take into consideration child hierarchies
        // of this dialog's blockers
        Window blockerToCheck = this;
        while (blockerToCheck != null) {
            Component c = w;
            while ((c != null) && (c != blockerToCheck)) {
                c = c.getParent_NoClientCode();
            }
            if (c == blockerToCheck) {
                return false;
            }
            blockerToCheck = blockerToCheck.getModalBlocker();
        }
        switch (modalityType) {
            case MODELESS:
                return false;
            case DOCUMENT_MODAL:
                if (w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE)) {
                    // application- and toolkit-excluded windows are not blocked by
                    // document-modal dialogs from outside their children hierarchy
                    Component c = this;
                    while ((c != null) && (c != w)) {
                        c = c.getParent_NoClientCode();
                    }
                    return c == w;
                } else {
                    return getDocumentRoot() == w.getDocumentRoot();
                }
            case APPLICATION_MODAL:
                return !w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE) &&
                    (appContext == w.appContext);
            case TOOLKIT_MODAL:
                return !w.isModalExcluded(ModalExclusionType.TOOLKIT_EXCLUDE);
        }

        return false;
    
public voidshow()
Makes the {@code Dialog} visible. If the dialog and/or its owner are not yet displayable, both are made displayable. The dialog will be validated prior to being made visible. If the dialog is already visible, this will bring the dialog to the front.

If the dialog is modal and is not already visible, this call will not return until the dialog is hidden by calling hide or dispose. It is permissible to show modal dialogs from the event dispatching thread because the toolkit will ensure that another event pump runs while the one which invoked this method is blocked.

see
Component#hide
see
Component#isDisplayable
see
Component#validate
see
#isModal
see
Window#setVisible(boolean)
deprecated
As of JDK version 1.5, replaced by {@link #setVisible(boolean) setVisible(boolean)}.

        beforeFirstShow = false;
        if (!isModal()) {
            conditionalShow(null, null);
        } else {
            // Set this variable before calling conditionalShow(). That
            // way, if the Dialog is hidden right after being shown, we
            // won't mistakenly block this thread.
            keepBlocking = true;

            // Store the app context on which this dialog is being shown.
            // Event dispatch thread of this app context will be sleeping until
            // we wake it by any event from hideAndDisposeHandler().
            showAppContext = AppContext.getAppContext();

            AtomicLong time = new AtomicLong();
            Component predictedFocusOwner = null;
            try {
                predictedFocusOwner = getMostRecentFocusOwner();
                if (conditionalShow(predictedFocusOwner, time)) {
                    // We have two mechanisms for blocking: 1. If we're on the
                    // EventDispatchThread, start a new event pump. 2. If we're
                    // on any other thread, call wait() on the treelock.

                    modalFilter = ModalEventFilter.createFilterForDialog(this);

                    final Runnable pumpEventsForFilter = new Runnable() {
                        public void run() {
                            EventDispatchThread dispatchThread =
                                (EventDispatchThread)Thread.currentThread();
                            dispatchThread.pumpEventsForFilter(new Conditional() {
                                public boolean evaluate() {
                                    return keepBlocking && windowClosingException == null;
                                }
                            }, modalFilter);
                        }
                    };

                    // if this dialog is toolkit-modal, the filter should be added
                    // to all EDTs (for all AppContexts)
                    if (modalityType == ModalityType.TOOLKIT_MODAL) {
                        Iterator it = AppContext.getAppContexts().iterator();
                        while (it.hasNext()) {
                            AppContext appContext = (AppContext)it.next();
                            if (appContext == showAppContext) {
                                continue;
                            }
                            EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                            // it may occur that EDT for appContext hasn't been started yet, so
                            // we post an empty invocation event to trigger EDT initialization
                            Runnable createEDT = new Runnable() {
                                public void run() {};
                            };
                            eventQueue.postEvent(new InvocationEvent(this, createEDT));
                            EventDispatchThread edt = eventQueue.getDispatchThread();
                            edt.addEventFilter(modalFilter);
                        }
                    }

                    modalityPushed();
                    try {
                        if (EventQueue.isDispatchThread()) {
                            /*
                             * dispose SequencedEvent we are dispatching on current
                             * AppContext, to prevent us from hang.
                             *
                             */
                            // BugId 4531693 (son@sparc.spb.su)
                            SequencedEvent currentSequencedEvent = KeyboardFocusManager.
                                getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
                            if (currentSequencedEvent != null) {
                                currentSequencedEvent.dispose();
                            }

                            /*
                             * Event processing is done inside doPrivileged block so that
                             * it wouldn't matter even if user code is on the stack 
                             * Fix for BugId 6300270
                             */

                             AccessController.doPrivileged(new PrivilegedAction() {
                                     public Object run() {
                                        pumpEventsForFilter.run();
                                        return null;
                                     }
                             });
                        } else {
                            synchronized (getTreeLock()) {
                                Toolkit.getEventQueue().postEvent(new PeerEvent(this,
                                                                                pumpEventsForFilter,
                                                                                PeerEvent.PRIORITY_EVENT));
                                while (keepBlocking && windowClosingException == null) {
                                    try {
                                        getTreeLock().wait();
                                    } catch (InterruptedException e) {
                                        break;
                                    }
                                }
                            }
                        }
                    } finally {
                        modalityPopped();
                    }

                    // if this dialog is toolkit-modal, its filter must be removed
                    // from all EDTs (for all AppContexts)
                    if (modalityType == ModalityType.TOOLKIT_MODAL) {
                        Iterator it = AppContext.getAppContexts().iterator();
                        while (it.hasNext()) {
                            AppContext appContext = (AppContext)it.next();
                            if (appContext == showAppContext) {
                                continue;
                            }
                            EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                            EventDispatchThread edt = eventQueue.getDispatchThread();
                            edt.removeEventFilter(modalFilter);
                        }
                    }

                    if (windowClosingException != null) {
                        windowClosingException.fillInStackTrace();
                        throw windowClosingException;
                    }
                }
            } finally {
                if (predictedFocusOwner != null) {
                    // Restore normal key event dispatching
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        dequeueKeyEvents(time.get(), predictedFocusOwner);
                }
            }
        }
    
public voidtoBack()
{@inheritDoc}

If this dialog is modal and blocks some windows, then all of them are also sent to the back to keep them below the blocking dialog.

see
java.awt.Window#toBack

        super.toBack();
        if (visible) {
            synchronized (getTreeLock()) {
                for (Window w : blockedWindows) {
                    w.toBack_NoClientCode();
                }
            }
        }
    
voidunblockWindow(java.awt.Window w)

        if (w.isModalBlocked() && blockedWindows.contains(w)) {
            blockedWindows.remove(w);
            w.setModalBlocked(this, false);
        }