Top Description Inners Fields Constructors Methods
java.awt

public Class Dialog

extends Window
Class Inheritance
Known Direct Subclasses
javax.swing.JDialog, java.awt.FileDialog
Imports
java.awt.event.ComponentEvent, .HierarchyEvent, .InvocationEvent, .WindowEvent, java.awt.peer.DialogPeer, java.io.IOException, .ObjectInputStream, .Serial, java.security.AccessControlException, .AccessController, .PrivilegedAction, java.util.Iterator, java.util.concurrent.atomic.AtomicLong, javax.accessibility.AccessibleContext, .AccessibleRole, .AccessibleState, .AccessibleStateSet, sun.awt.AWTPermissions, .AppContext, .SunToolkit, sun.awt.util.IdentityArrayList

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 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 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.

Authors
Sami Shaio, Arthur van Hoff
Since
1.0
See Also
WindowEvent, Window#addWindowListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
Dialog.AccessibleAWTDialog

This class implements accessibility support for the Dialog class.

public static enum
Dialog.ModalExclusionType

Any top-level window can be marked not to be blocked by modal dialogs.

public static enum
Dialog.ModalityType

Modal dialogs block all input to some top-level windows.

Field Summary

Modifier and TypeField and Description
private static final String
pack-priv transient IdentityArrayList<Window>
public static final Dialog.ModalityType
DEFAULT_MODALITY_TYPE

Default modality type for modal dialogs.

private transient boolean
pack-priv transient volatile boolean
pack-priv transient volatile boolean
pack-priv boolean
modal

True if this dialog is modal, false is the dialog is modeless.

pack-priv static transient IdentityArrayList<Dialog>
private transient ModalEventFilter
pack-priv Dialog.ModalityType
modalityType

Modality type of this dialog.

private static int
pack-priv boolean
resizable

A dialog's resizable property.

private transient volatile SecondaryLoop
private static final long
serialVersionUID

Hides java.awt.Window.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
pack-priv String
title

Specifies the title of the Dialog.

pack-priv boolean
undecorated

This field indicates whether the dialog is undecorated.

Inherited from java.awt.Window:
anchorbeforeFirstShowdisposerRecordiconsinputContextisInShowisTrayIconWindowmodalBlockermodalExclusionTypeOPENEDownedWindowListshowWithParentstatesyncLWRequestssystemSyncLWRequestswarningStringwindowFocusListenerwindowListenerwindowStateListener

Constructor Summary

AccessConstructor and Description
public
Dialog(Frame
the owner of the dialog or null if this dialog has no owner
owner
)

Constructs an initially invisible, modeless Dialog with the specified owner Frame and an empty title.

public
Dialog(Frame
the owner of the dialog or null if this dialog has no owner
owner
,
boolean
specifies 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
modal
)

Constructs an initially invisible Dialog with the specified owner Frame and modality and an empty title.

public
Dialog(Frame
the owner of the dialog or null if this dialog has no owner
owner
,
String
the title of the dialog or null if this dialog has no title
title
)

Constructs an initially invisible, modeless Dialog with the specified owner Frame and title.

public
Dialog(Frame
the owner of the dialog or null if this dialog has no owner
owner
,
String
the title of the dialog or null if this dialog has no title
title
,
boolean
specifies 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
modal
)

Constructs an initially invisible Dialog with the specified owner Frame, title and modality.

public
Dialog(Frame
the owner of the dialog or null if this dialog has no owner
owner
,
String
the title of the dialog or null if this dialog has no title
title
,
boolean
specifies 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
modal
,
GraphicsConfiguration
the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
gc
)

Constructs an initially invisible Dialog with the specified owner Frame, title, modality, and GraphicsConfiguration.

public
Dialog(Dialog
the owner of the dialog or null if this dialog has no owner
owner
)

Constructs an initially invisible, modeless Dialog with the specified owner Dialog and an empty title.

public
Dialog(Dialog
the owner of the dialog or null if this has no owner
owner
,
String
the title of the dialog or null if this dialog has no title
title
)

Constructs an initially invisible, modeless Dialog with the specified owner Dialog and title.

public
Dialog(Dialog
the owner of the dialog or null if this dialog has no owner
owner
,
String
the title of the dialog or null if this dialog has no title
title
,
boolean
specifies 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
modal
)

Constructs an initially invisible Dialog with the specified owner Dialog, title, and modality.

public
Dialog(Dialog
the owner of the dialog or null if this dialog has no owner
owner
,
String
the title of the dialog or null if this dialog has no title
title
,
boolean
specifies 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
modal
,
GraphicsConfiguration
the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
gc
)

Constructs an initially invisible Dialog with the specified owner Dialog, title, modality and GraphicsConfiguration.

public
Dialog(Window
the owner of the dialog. The owner must be an instance of Dialog, Frame, any of their descendants or null
owner
)

Constructs an initially invisible, modeless Dialog with the specified owner Window and an empty title.

public
Dialog(Window
the owner of the dialog. The owner must be an instance of Dialog, Frame, any of their descendants or null
owner
,
String
the title of the dialog or null if this dialog has no title
title
)

Constructs an initially invisible, modeless Dialog with the specified owner Window and title.

public
Dialog(Window
the owner of the dialog. The owner must be an instance of Dialog, Frame, any of their descendants or null
owner
,
Dialog.ModalityType
specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
modalityType
)

Constructs an initially invisible Dialog with the specified owner Window and modality and an empty title.

public
Dialog(Window
the owner of the dialog. The owner must be an instance of Dialog, Frame, any of their descendants or null
owner
,
String
the title of the dialog or null if this dialog has no title
title
,
Dialog.ModalityType
specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
modalityType
)

Constructs an initially invisible Dialog with the specified owner Window, title and modality.

public
Dialog(Window
the owner of the dialog. The owner must be an instance of Dialog, Frame, any of their descendants or null
owner
,
String
the title of the dialog or null if this dialog has no title
title
,
Dialog.ModalityType
specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
modalityType
,
GraphicsConfiguration
the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
gc
)

Constructs an initially invisible Dialog with the specified owner Window, title, modality and GraphicsConfiguration.

Method Summary

Modifier and TypeMethod and Description
public void
addNotify()

Overrides java.awt.Window.addNotify.

Makes this Dialog displayable by connecting it to a native screen resource.
pack-priv void
pack-priv void
private void
pack-priv static void
private boolean

Returns:

true if we actually showed, false if we just called toFront()
conditionalShow
(Component toFocus, AtomicLong time)

pack-priv String
constructComponentName()

Overrides java.awt.Window.constructComponentName.

Construct a name for this component.
pack-priv void
doDispose()

Overrides java.awt.Window.doDispose.

Disposes the Dialog and then causes show() to return if it is currently blocked.
public AccessibleContext

Returns:

an AccessibleAWTDialog that serves as the AccessibleContext of this Dialog
getAccessibleContext
()

Overrides java.awt.Window.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this Dialog.
public Dialog.ModalityType

Returns:

modality type of this dialog
getModalityType
()

Returns the modality type of this dialog.

public String

Returns:

the title of this dialog window. The title may be null.
getTitle
()

Gets the title of the dialog.

public void
hide()

Overrides java.awt.Window.hide.

Deprecated As of JDK version 1.5, replaced by setVisible(boolean).
Hides the Dialog and then causes show to return if it is currently blocked.
private void
private void
private static native void
initIDs()

Hides java.awt.Window.initIDs.

Initialize JNI field and method IDs
public boolean

Returns:

true if this dialog window is modal; false otherwise
isModal
()

Indicates whether the dialog is modal.

pack-priv final boolean
public boolean

Returns:

true if the user can resize the dialog; false otherwise.
isResizable
()

Indicates whether this dialog is resizable by the user.

public boolean

Returns:

true if dialog is undecorated; false otherwise.
isUndecorated
()

Indicates whether this dialog is undecorated.

pack-priv void
pack-priv final void
pack-priv final void
pack-priv void
protected String

Returns:

the parameter string of this dialog window.
paramString
()

Overrides java.awt.Container.paramString.

Returns a string representing the state of this dialog.
private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Hides java.awt.Window.readObject.

Reads serializable fields from stream.
public void
setBackground(Color
the color to become this window's background color.
bgColor
)

Overrides java.awt.Window.setBackground.

Sets the background color of this window.
public void
setModal(boolean
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 equivalent to setModalityType(Dialog.ModalityType.MODELESS)
modal
)

Specifies whether this dialog should be modal.

public void
setModalityType(Dialog.ModalityType
specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
type
)

Sets the modality type for this dialog.

public void
setOpacity(float
the opacity level to set to the window
opacity
)

Overrides java.awt.Window.setOpacity.

Sets the opacity of the window.
public void
setResizable(boolean
true if the user can resize this dialog; false otherwise.
resizable
)

Sets whether this dialog is resizable by the user.

public void
setShape(Shape
the shape to set to the window
shape
)

Overrides java.awt.Window.setShape.

Sets the shape of the window.
public void
setTitle(String
the title displayed in the dialog's border; a null value results in an empty title
title
)

Sets the title of the Dialog.

public void
setUndecorated(boolean
true if no dialog decorations are to be enabled; false if dialog decorations are to be enabled
undecorated
)

Disables or enables decorations for this dialog.

public void
setVisible(boolean
if true, makes the Dialog visible, otherwise hides the 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 false, hides the Dialog and then causes setVisible(true) to return if it is currently blocked.

Notes for modal dialogs.

  • setVisible(true): If the dialog is not already visible, this call will not return until the dialog is hidden by calling setVisible(false) or dispose.
  • setVisible(false): Hides the dialog and then returns on 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.
b
)

Overrides java.awt.Window.setVisible.

Shows or hides this Dialog depending on the value of parameter b.
pack-priv boolean
public void
show()

Overrides java.awt.Window.show.

Deprecated As of JDK version 1.5, replaced by setVisible(boolean).
Makes the Dialog visible.
public void
toBack()

Overrides java.awt.Window.toBack.

If this Window is visible, sends this Window to the back and may cause it to lose focus or activation if it is the focused or active Window.
pack-priv void
Inherited from java.awt.Window:
addOwnedWindowaddPropertyChangeListeneraddPropertyChangeListeneraddWindowFocusListeneraddWindowListeneraddWindowStateListeneradjustDescendantsOnParentadjustListeningChildrenOnParentapplyCompoundShapeapplyCurrentShapeapplyResourceBundleapplyResourceBundlecanContainFocusOwnerclearMostRecentFocusOwnerOnHidecloseSplashScreenconnectOwnedWindowcreateBufferStrategycreateBufferStrategydeliverMouseWheelToAncestordispatchEventImpldispatchMouseWheelToAncestordisposedisposeImpleventEnabledgetAllUnblockedWindowsgetAllWindowsgetBackgroundgetBufferStrategygetContainergetDocumentRootgetFocusableWindowStategetFocusCycleRootAncestorgetFocusOwnergetFocusTraversalKeysgetIconImagesgetInputContextgetListenersgetLocalegetLocationOnWindowgetModalBlockergetModalExclusionTypegetMostRecentFocusOwnergetOpacitygetOwnedWindowsgetOwnedWindows_NoClientCodegetOwnergetOwner_NoClientCodegetOwnerlessWindowsgetShapegetTemporaryLostComponentgetToolkitgetTypegetWarningStringgetWindowFocusListenersgetWindowListenersgetWindowsgetWindowStateListenersisActiveisAlwaysOnTopisAlwaysOnTopSupportedisAutoRequestFocusisDisposingisFocusableWindowisFocusCycleRootisFocusedisLocationByPlatformisModalBlockedisModalExcludedisOpaqueisRecursivelyVisibleisShowingisValidateRootmixOnReshapingpackpaintpostEventpostProcessKeyEventpostWindowEventpreProcessKeyEventprocessEventprocessWindowEventprocessWindowFocusEventprocessWindowStateEventremoveNotifyremoveOwnedWindowremoveWindowFocusListenerremoveWindowListenerremoveWindowStateListenerreshapesetAlwaysOnTopsetAutoRequestFocussetBoundssetBoundssetClientSizesetCursorsetFocusableWindowStatesetFocusCycleRootsetGraphicsConfigurationsetIconImagesetIconImagessetLocationsetLocationsetLocationByPlatformsetLocationRelativeTosetMinimumSizesetModalBlockedsetModalExclusionTypesetSizesetSizesetTemporaryLostComponentsetTypetoBack_NoClientCodetoFronttoFront_NoClientCodeupdateChildFocusableWindowStateupdateChildrenBlockingupdateZOrder