APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class JDialog

extends Dialog
implements WindowConstants, Accessible, RootPaneContainer, HasGetTransferHandler
Class Inheritance
All Implemented Interfaces
javax.swing.TransferHandler.HasGetTransferHandler, javax.swing.RootPaneContainer, javax.accessibility.Accessible, javax.swing.WindowConstants
Known Direct Subclasses
sun.print.ServiceDialog, javax.swing.ColorChooserDialog
Annotations
@JavaBean
defaultProperty:JMenuBar
description:A toplevel window for creating dialog boxes.
@SwingContainer
delegate:getContentPane
@SuppressWarnings:serial
Imports
java.awt.*, java.awt.event.*, java.beans.JavaBean, .BeanProperty, javax.accessibility.*

The main class for creating a dialog window. You can use this class to create a custom dialog, or invoke the many class methods in JOptionPane to create a variety of standard dialogs. For information about creating dialogs, see The Java Tutorial section How to Make Dialogs.

The JDialog component contains a JRootPane as its only child. The contentPane should be the parent of any children of the JDialog. As a convenience, the add, remove, and setLayout methods of this class are overridden, so that they delegate calls to the corresponding methods of the ContentPane. For example, you can add a child component to a dialog as follows:

      dialog.add(child);
And the child will be added to the contentPane. The contentPane is always non-null. Attempting to set it to null generates an exception. The default contentPane has a BorderLayout manager set on it. Refer to javax.swing.RootPaneContainer for details on adding, removing and setting the LayoutManager of a JDialog.

Please see the JRootPane documentation for a complete description of the contentPane, glassPane, and layeredPane components.

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

Warning

Swing is not thread safe. For more information see Swing's Threading Policy.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Authors
David Kloba, James Gosling, Scott Violet
Since
1.2
See Also
JOptionPane, JRootPane, javax.swing.RootPaneContainer

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JDialog.AccessibleJDialog

This class implements accessibility support for the JDialog class.

Field Summary

Modifier and TypeField and Description
protected AccessibleContext
accessibleContext

Hides java.awt.Component.accessibleContext.

AccessibleContext associated with this JDialog
private int
private static boolean
protected JRootPane
rootPane

The JRootPane instance that manages the contentPane.

protected boolean
rootPaneCheckingEnabled

If true then calls to add and setLayout will be forwarded to the contentPane.

private TransferHandler
transferHandler

The TransferHandler for this dialog.

Inherited from java.awt.Dialog:
DEFAULT_MODALITY_TYPE

Constructor Summary

AccessConstructor and Description
public
JDialog()

Creates a modeless dialog without a title and without a specified Frame owner.

public
JDialog(Frame
the Frame from which the dialog is displayed
owner
)

Creates a modeless dialog with the specified Frame as its owner and an empty title.

public
JDialog(Frame
the Frame from which the dialog is displayed
owner
,
boolean
specifies whether dialog blocks user input to other top-level windows when shown. If true, the modality type property is set to DEFAULT_MODALITY_TYPE, otherwise the dialog is modeless.
modal
)

Creates a dialog with an empty title and the specified modality and Frame as its owner.

public
JDialog(Frame
the Frame from which the dialog is displayed
owner
,
String
the String to display in the dialog's title bar
title
)

Creates a modeless dialog with the specified title and with the specified owner frame.

public
JDialog(Frame
the Frame from which the dialog is displayed
owner
,
String
the String to display in the dialog's title bar
title
,
boolean
specifies whether dialog blocks user input to other top-level windows when shown. If true, the modality type property is set to DEFAULT_MODALITY_TYPE otherwise the dialog is modeless
modal
)

Creates a dialog with the specified title, owner Frame and modality.

public
JDialog(Frame
the Frame from which the dialog is displayed
owner
,
String
the String to display in the dialog's title bar
title
,
boolean
specifies whether dialog blocks user input to other top-level windows when shown. If true, the modality type property is set to DEFAULT_MODALITY_TYPE, otherwise the dialog is modeless.
modal
,
GraphicsConfiguration
the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
gc
)

Creates a dialog with the specified title, owner Frame, modality and GraphicsConfiguration.

public
JDialog(Dialog
the owner Dialog from which the dialog is displayed or null if this dialog has no owner
owner
)

Creates a modeless dialog with the specified Dialog as its owner and an empty title.

public
JDialog(Dialog
the owner Dialog from which the dialog is displayed or null if this dialog has no owner
owner
,
boolean
specifies whether dialog blocks user input to other top-level windows when shown. If true, the modality type property is set to DEFAULT_MODALITY_TYPE, otherwise the dialog is modeless.
modal
)

Creates a dialog with an empty title and the specified modality and Dialog as its owner.

public
JDialog(Dialog
the owner Dialog from which the dialog is displayed or null if this dialog has no owner
owner
,
String
the String to display in the dialog's title bar
title
)

Creates a modeless dialog with the specified title and with the specified owner dialog.

public
JDialog(Dialog
the owner Dialog from which the dialog is displayed or null if this dialog has no owner
owner
,
String
the String to display in the dialog's title bar
title
,
boolean
specifies whether dialog blocks user input to other top-level windows when shown. If true, the modality type property is set to DEFAULT_MODALITY_TYPE, otherwise the dialog is modeless
modal
)

Creates a dialog with the specified title, modality and the specified owner Dialog.

public
JDialog(Dialog
the owner Dialog from which the dialog is displayed or null if this dialog has no owner
owner
,
String
the String to display in the dialog's title bar
title
,
boolean
specifies whether dialog blocks user input to other top-level windows when shown. If true, the modality type property is set to DEFAULT_MODALITY_TYPE, otherwise the dialog is modeless
modal
,
GraphicsConfiguration
the GraphicsConfiguration of the target screen device; if null, the default system GraphicsConfiguration is assumed
gc
)

Creates a dialog with the specified title, owner Dialog, modality and GraphicsConfiguration.

public
JDialog(Window
the Window from which the dialog is displayed or null if this dialog has no owner
owner
)

Creates a modeless dialog with the specified Window as its owner and an empty title.

public
JDialog(Window
the Window from which the dialog is displayed or null if this dialog has no owner
owner
,
Dialog.ModalityType
specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
modalityType
)

Creates a dialog with an empty title and the specified modality and Window as its owner.

public
JDialog(Window
the Window from which the dialog is displayed or null if this dialog has no owner
owner
,
String
the String to display in the dialog's title bar or null if the dialog has no title
title
)

Creates a modeless dialog with the specified title and owner Window.

public
JDialog(Window
the Window from which the dialog is displayed or null if this dialog has no owner
owner
,
String
the String to display in the dialog's title bar or null if the 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
)

Creates a dialog with the specified title, owner Window and modality.

public
JDialog(Window
the Window from which the dialog is displayed or null if this dialog has no owner
owner
,
String
the String to display in the dialog's title bar or null if the 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
)

Creates a dialog with the specified title, owner Window, modality and GraphicsConfiguration.

Method Summary

Modifier and TypeMethod and Description
protected void
addImpl(Component
the component to be enhanced
comp
,
Object
the constraints to be respected
constraints
,
int
the index
index
)

Overrides java.awt.Container.addImpl.

Adds the specified child Component.

protected JRootPane

Returns:

a new JRootPane
createRootPane
()

Called by the constructor methods to create the default rootPane.

protected void
dialogInit()

Called by the constructors to init the JDialog properly.

public AccessibleContext

Returns:

an AccessibleJDialog that serves as the AccessibleContext of this JDialog
getAccessibleContext
()

Overrides java.awt.Dialog.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JDialog.

public Container

Returns:

the contentPane property
getContentPane
()

Implements javax.swing.RootPaneContainer.getContentPane.

Returns the contentPane object for this dialog.

public int

Returns:

an integer indicating the window-close operation
getDefaultCloseOperation
()

Returns the operation which occurs when the user initiates a "close" on this dialog.

public Component

Returns:

the glassPane property
getGlassPane
()

Implements javax.swing.RootPaneContainer.getGlassPane.

Returns the glassPane object for this dialog.

public Graphics
getGraphics()

Overrides java.awt.Component.getGraphics.

Creates a graphics context for this component.

public JMenuBar

Returns:

the menubar set on this dialog
getJMenuBar
()

Returns the menubar set on this dialog.

public JLayeredPane

Returns:

the layeredPane property
getLayeredPane
()

Implements javax.swing.RootPaneContainer.getLayeredPane.

Returns the layeredPane object for this dialog.

public JRootPane
getRootPane()

Implements javax.swing.RootPaneContainer.getRootPane.

Returns the rootPane object for this dialog.

public TransferHandler

Returns:

the value of the transferHandler property
getTransferHandler
()

Implements javax.swing.TransferHandler.HasGetTransferHandler.getTransferHandler.

Gets the transferHandler property.

public static boolean

Returns:

true if look and feel should provide Window decorations.
isDefaultLookAndFeelDecorated
()

Returns true if newly created JDialogs should have their Window decorations provided by the current look and feel.

protected boolean

Returns:

true if add and setLayout are forwarded; false otherwise
isRootPaneCheckingEnabled
()

Returns whether calls to add and setLayout are forwarded to the contentPane.

protected String

Returns:

a string representation of this JDialog.
paramString
()

Overrides java.awt.Dialog.paramString.

Returns a string representation of this JDialog.

protected void
processWindowEvent(WindowEvent e)

Overrides java.awt.Window.processWindowEvent.

Handles window events depending on the state of the defaultCloseOperation property.

public void
remove(Component
the component to be removed
comp
)

Overrides java.awt.Container.remove.

Removes the specified component from the container.

public void
repaint(long
maximum time in milliseconds before update
time
,
int
the x coordinate
x
,
int
the y coordinate
y
,
int
the width
width
,
int
the height
height
)

Overrides java.awt.Component.repaint.

Repaints the specified rectangle of this component within time milliseconds.

public void
setContentPane(Container
the contentPane object for this dialog
contentPane
)

Implements javax.swing.RootPaneContainer.setContentPane.

Sets the contentPane property.

public void
setDefaultCloseOperation(int
the operation which should be performed when the user closes the dialog
operation
)

Sets the operation that will happen by default when the user initiates a "close" on this dialog.

public static void
setDefaultLookAndFeelDecorated(boolean
A hint as to whether or not current look and feel should provide window decorations
defaultLookAndFeelDecorated
)

Provides a hint as to whether or not newly created JDialogs should have their Window decorations (such as borders, widgets to close the window, title...) provided by the current look and feel.

public void
setGlassPane(Component
the glassPane object for this dialog
glassPane
)

Implements javax.swing.RootPaneContainer.setGlassPane.

Sets the glassPane property.

public void
setJMenuBar(final JMenuBar
the menubar being placed in the dialog
menu
)

Sets the menubar for this dialog.

public void
setLayeredPane(JLayeredPane
the new layeredPane property
layeredPane
)

Implements javax.swing.RootPaneContainer.setLayeredPane.

Sets the layeredPane property.

public void
setLayout(LayoutManager
the LayoutManager
manager
)

Overrides java.awt.Container.setLayout.

Sets the LayoutManager.

protected void
setRootPane(JRootPane
the rootPane object for this dialog
root
)

Sets the rootPane property.

protected void
setRootPaneCheckingEnabled(boolean
true if add and setLayout are forwarded, false if they should operate directly on the JDialog.
enabled
)

Sets whether calls to add and setLayout are forwarded to the contentPane.

public void
setTransferHandler(TransferHandler
the new TransferHandler
newHandler
)

Sets the transferHandler property, which is a mechanism to support transfer of data into this component.

public void
update(Graphics
the Graphics context in which to paint
g
)

Overrides java.awt.Container.update.

Calls paint(g).

Inherited from java.awt.Dialog:
addNotifygetModalityTypegetTitlehideisModalisResizableisUndecoratedsetBackgroundsetModalsetModalityTypesetOpacitysetResizablesetShapesetTitlesetUndecoratedsetVisibleshowtoBack