FileDocCategorySizeDatePackage
JDialog.javaAPI DocJava SE 6 API47911Tue Jun 10 00:26:36 BST 2008javax.swing

JDialog

public class JDialog extends Dialog implements WindowConstants, RootPaneContainer, TransferHandler$HasGetTransferHandler, Accessible
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 {@link 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 add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary. This means you can write:

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 {@link 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 {@link 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 JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

see
JOptionPane
see
JRootPane
see
javax.swing.RootPaneContainer
beaninfo
attribute: isContainer true attribute: containerDelegate getContentPane description: A toplevel window for creating dialog boxes.
version
1.93 08/08/06
author
David Kloba
author
James Gosling
author
Scott Violet

Fields Summary
private static final Object
defaultLookAndFeelDecoratedKey
Key into the AppContext, used to check if should provide decorations by default.
private int
defaultCloseOperation
protected JRootPane
rootPane
protected boolean
rootPaneCheckingEnabled
If true then calls to add and setLayout will be forwarded to the contentPane. This is initially false, but is set to true when the JDialog is constructed.
private TransferHandler
transferHandler
The TransferHandler for this dialog.
protected AccessibleContext
accessibleContext
Constructors Summary
public JDialog()
Creates a modeless dialog without a title and without a specified Frame owner. A shared, hidden frame will be set as the owner of the dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

NOTE: This constructor does not allow you to create an unowned JDialog. To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale


                                                                                                      
      
        this((Frame)null, false);
    
public JDialog(Dialog owner, String title, boolean modal)
Creates a dialog with the specified title, modality and the specified owner Dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the owner Dialog from which the dialog is displayed or null if this dialog has no owner
param
title the String to display in the dialog's title bar
param
modal 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
exception
HeadlessException if 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
JComponent#getDefaultLocale

        super(owner, title, modal);
        dialogInit();
    
public JDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc)
Creates a dialog with the specified title, owner Dialog, modality and GraphicsConfiguration.

NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the owner Dialog from which the dialog is displayed or null if this dialog has no owner
param
title the String to display in the dialog's title bar
param
modal 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
param
gc the GraphicsConfiguration of the target screen device. If gc is null, the same GraphicsConfiguration as the owning Dialog is used.
exception
HeadlessException if 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
JComponent#getDefaultLocale
since
1.4

        super(owner, title, modal, gc);
        dialogInit();
    
public JDialog(Window owner)
Creates a modeless dialog with the specified owner Window and an empty title.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the Window from which the dialog is displayed or null if this dialog has no owner
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale
since
1.6

        this(owner, Dialog.ModalityType.MODELESS);
    
public JDialog(Window owner, ModalityType modalityType)
Creates a dialog with the specified owner Window, modality and an empty title.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the Window from which the dialog is displayed or null if this dialog has no owner
param
modalityType specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
exception
HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale
since
1.6

        this(owner, null, modalityType);
    
public JDialog(Window owner, String title)
Creates a modeless dialog with the specified title and owner Window.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the Window from which the dialog is displayed or null if this dialog has no owner
param
title the String to display in the dialog's title bar or null if the dialog has no title
exception
java.awt.HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale
since
1.6

        this(owner, title, Dialog.ModalityType.MODELESS);     
    
public JDialog(Window owner, String title, Dialog$ModalityType modalityType)
Creates a dialog with the specified title, owner Window and modality.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the Window from which the dialog is displayed or null if this dialog has no owner
param
title the String to display in the dialog's title bar or null if the 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.awt.HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale
since
1.6

        super(owner, title, modalityType);
        dialogInit();
    
public JDialog(Window owner, String title, Dialog$ModalityType modalityType, GraphicsConfiguration gc)
Creates a dialog with the specified title, owner Window, modality and GraphicsConfiguration.

NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the Window from which the dialog is displayed or null if this dialog has no owner
param
title the String to display in the dialog's title bar or null if the 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 GraphicsConfiguration from the owning window is used; if owner is also null, the system default GraphicsConfiguration is assumed
exception
java.awt.HeadlessException when GraphicsEnvironment.isHeadless() returns true
see
java.awt.Dialog.ModalityType
see
java.awt.Dialog#setModal
see
java.awt.Dialog#setModalityType
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale
since
1.6

        super(owner, title, modalityType, gc);
        dialogInit();
    
public JDialog(Frame owner)
Creates a modeless dialog without a title with the specified Frame as its owner. If owner is null, a shared, hidden frame will be set as the owner of the dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

NOTE: This constructor does not allow you to create an unowned JDialog. To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

param
owner the Frame from which the dialog is displayed
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale

        this(owner, false);
    
public JDialog(Frame owner, boolean modal)
Creates a dialog with the specified owner Frame, modality and an empty title. If owner is null, a shared, hidden frame will be set as the owner of the dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

NOTE: This constructor does not allow you to create an unowned JDialog. To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

param
owner the Frame from which the dialog is displayed
param
modal 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.
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale

        this(owner, null, modal);
    
public JDialog(Frame owner, String title)
Creates a modeless dialog with the specified title and with the specified owner frame. If owner is null, a shared, hidden frame will be set as the owner of the dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

NOTE: This constructor does not allow you to create an unowned JDialog. To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

param
owner the Frame from which the dialog is displayed
param
title the String to display in the dialog's title bar
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale

        this(owner, title, false);     
    
public JDialog(Frame owner, String title, boolean modal)
Creates a dialog with the specified title, owner Frame and modality. If owner is null, a shared, hidden frame will be set as the owner of this dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.

NOTE: This constructor does not allow you to create an unowned JDialog. To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

param
owner the Frame from which the dialog is displayed
param
title the String to display in the dialog's title bar
param
modal 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
exception
HeadlessException if 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
JComponent#getDefaultLocale

        super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner, 
              title, modal);
 	if (owner == null) {
	    WindowListener ownerShutdownListener =
		(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
 	    addWindowListener(ownerShutdownListener);
 	}
        dialogInit();
    
public JDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)
Creates a dialog with the specified title, owner Frame, modality and GraphicsConfiguration. If owner is null, a shared, hidden frame will be set as the owner of this dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.

NOTE: This constructor does not allow you to create an unowned JDialog. To create an unowned JDialog you must use either the JDialog(Window) or JDialog(Dialog) constructor with an argument of null.

param
owner the Frame from which the dialog is displayed
param
title the String to display in the dialog's title bar
param
modal 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.
param
gc the GraphicsConfiguration of the target screen device. If gc is null, the same GraphicsConfiguration as the owning Frame is used.
exception
HeadlessException if 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
JComponent#getDefaultLocale
since
1.4

        super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner, 
              title, modal, gc);
 	if (owner == null) {
	    WindowListener ownerShutdownListener =
		(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
 	    addWindowListener(ownerShutdownListener);
 	}
        dialogInit();
    
public JDialog(Dialog owner)
Creates a modeless dialog without a title with the specified Dialog as its owner.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the owner Dialog from which the dialog is displayed or null if this dialog has no owner
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale

        this(owner, false);
    
public JDialog(Dialog owner, boolean modal)
Creates a dialog with the specified owner Dialog and modality.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the owner Dialog from which the dialog is displayed or null if this dialog has no owner
param
modal 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.
exception
HeadlessException if 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
JComponent#getDefaultLocale

        this(owner, null, modal);
    
public JDialog(Dialog owner, String title)
Creates a modeless dialog with the specified title and with the specified owner dialog.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

param
owner the owner Dialog from which the dialog is displayed or null if this dialog has no owner
param
title the String to display in the dialog's title bar
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
see
JComponent#getDefaultLocale

        this(owner, title, false);     
    
Methods Summary
protected voidaddImpl(java.awt.Component comp, java.lang.Object constraints, int index)
Adds the specified child Component. This method is overridden to conditionally forward calls to the contentPane. By default, children are added to the contentPane instead of the frame, refer to {@link javax.swing.RootPaneContainer} for details.

param
comp the component to be enhanced
param
constraints the constraints to be respected
param
index the index
exception
IllegalArgumentException if index is invalid
exception
IllegalArgumentException if adding the container's parent to itself
exception
IllegalArgumentException if adding a window to a container
see
#setRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer

        if(isRootPaneCheckingEnabled()) {
            getContentPane().add(comp, constraints, index);
        }
        else {
            super.addImpl(comp, constraints, index);
        }
    
protected javax.swing.JRootPanecreateRootPane()
Called by the constructor methods to create the default rootPane.

        JRootPane rp = new JRootPane();
        // NOTE: this uses setOpaque vs LookAndFeel.installProperty as there
        // is NO reason for the RootPane not to be opaque. For painting to
        // work the contentPane must be opaque, therefor the RootPane can
        // also be opaque.
        rp.setOpaque(true);
        return rp;
    
protected voiddialogInit()
Called by the constructors to init the JDialog properly.

        enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
        setLocale( JComponent.getDefaultLocale() );
        setRootPane(createRootPane());
        setRootPaneCheckingEnabled(true);
        if (JDialog.isDefaultLookAndFeelDecorated()) {
            boolean supportsWindowDecorations = 
            UIManager.getLookAndFeel().getSupportsWindowDecorations();
            if (supportsWindowDecorations) {
                setUndecorated(true);
                getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
            }
        }
        sun.awt.SunToolkit.checkAndSetPolicy(this, true);
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this JDialog. For JDialogs, the AccessibleContext takes the form of an AccessibleJDialog. A new AccessibleJDialog instance is created if necessary.

return
an AccessibleJDialog that serves as the AccessibleContext of this JDialog


                                                         
       
        if (accessibleContext == null) {
            accessibleContext = new AccessibleJDialog();
        }
        return accessibleContext;
    
public java.awt.ContainergetContentPane()
Returns the contentPane object for this dialog.

return
the contentPane property
see
#setContentPane
see
RootPaneContainer#getContentPane

 
        return getRootPane().getContentPane(); 
    
public intgetDefaultCloseOperation()
Returns the operation which occurs when the user initiates a "close" on this dialog.

return
an integer indicating the window-close operation
see
#setDefaultCloseOperation

        return defaultCloseOperation;
    
public java.awt.ComponentgetGlassPane()
Returns the glassPane object for this dialog.

return
the glassPane property
see
#setGlassPane
see
RootPaneContainer#getGlassPane

 
        return getRootPane().getGlassPane(); 
    
public java.awt.GraphicsgetGraphics()
{@inheritDoc}

since
1.6

        JComponent.getGraphicsInvoked(this);
        return super.getGraphics();
    
public javax.swing.JMenuBargetJMenuBar()
Returns the menubar set on this dialog.

see
#setJMenuBar

 
        return getRootPane().getMenuBar(); 
    
public javax.swing.JLayeredPanegetLayeredPane()
Returns the layeredPane object for this dialog.

return
the layeredPane property
see
#setLayeredPane
see
RootPaneContainer#getLayeredPane

 
        return getRootPane().getLayeredPane(); 
    
public javax.swing.JRootPanegetRootPane()
Returns the rootPane object for this dialog.

see
#setRootPane
see
RootPaneContainer#getRootPane

 
        return rootPane; 
    
public javax.swing.TransferHandlergetTransferHandler()
Gets the transferHandler property.

return
the value of the transferHandler property
see
TransferHandler
see
#setTransferHandler
since
1.6

        return transferHandler;
    
public static booleanisDefaultLookAndFeelDecorated()
Returns true if newly created JDialogs should have their Window decorations provided by the current look and feel. This is only a hint, as certain look and feels may not support this feature.

return
true if look and feel should provide Window decorations.
since
1.4

        Boolean defaultLookAndFeelDecorated = 
            (Boolean) SwingUtilities.appContextGet(defaultLookAndFeelDecoratedKey);
        if (defaultLookAndFeelDecorated == null) {
            defaultLookAndFeelDecorated = Boolean.FALSE;
        }
        return defaultLookAndFeelDecorated.booleanValue();
    
protected booleanisRootPaneCheckingEnabled()
Returns whether calls to add and setLayout are forwarded to the contentPane.

return
true if add and setLayout are fowarded; false otherwise
see
#addImpl
see
#setLayout
see
#setRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer

        return rootPaneCheckingEnabled;
    
protected java.lang.StringparamString()
Returns a string representation of this JDialog. 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
a string representation of this JDialog.

        String defaultCloseOperationString;
        if (defaultCloseOperation == HIDE_ON_CLOSE) {
            defaultCloseOperationString = "HIDE_ON_CLOSE";
        } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) {
            defaultCloseOperationString = "DISPOSE_ON_CLOSE";
        } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) {
            defaultCloseOperationString = "DO_NOTHING_ON_CLOSE";
        } else defaultCloseOperationString = "";
	String rootPaneString = (rootPane != null ?
				 rootPane.toString() : "");
	String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ?
						"true" : "false");

	return super.paramString() +
	",defaultCloseOperation=" + defaultCloseOperationString +
	",rootPane=" + rootPaneString +
	",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
    
protected voidprocessWindowEvent(java.awt.event.WindowEvent e)
Handles window events depending on the state of the defaultCloseOperation property.

see
#setDefaultCloseOperation

        super.processWindowEvent(e);

        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            switch(defaultCloseOperation) {
              case HIDE_ON_CLOSE:
                 setVisible(false);
                 break;
              case DISPOSE_ON_CLOSE:
                 dispose();
                 break;
              case DO_NOTHING_ON_CLOSE:
                 default: 
                 break;
            }
        }
    
public voidremove(java.awt.Component comp)
Removes the specified component from the container. If comp is not the rootPane, this will forward the call to the contentPane. This will do nothing if comp is not a child of the JDialog or contentPane.

param
comp the component to be removed
throws
NullPointerException if comp is null
see
#add
see
javax.swing.RootPaneContainer

	if (comp == rootPane) {
	    super.remove(comp);
	} else {
	    getContentPane().remove(comp);
	}
    
public voidrepaint(long time, int x, int y, int width, int height)
Repaints the specified rectangle of this component within time milliseconds. Refer to RepaintManager for details on how the repaint is handled.

param
time maximum time in milliseconds before update
param
x the x coordinate
param
y the y coordinate
param
width the width
param
height the height
see
RepaintManager
since
1.6

        if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
            RepaintManager.currentManager(this).addDirtyRegion(
                              this, x, y, width, height);
        }
        else {
            super.repaint(time, x, y, width, height);
        }
    
public voidsetContentPane(java.awt.Container contentPane)
Sets the contentPane property. This method is called by the constructor.

Swing's painting architecture requires an opaque JComponent in the containment hiearchy. This is typically provided by the content pane. If you replace the content pane it is recommended you replace it with an opaque JComponent.

see
JRootPane
param
contentPane the contentPane object for this dialog
exception
java.awt.IllegalComponentStateException (a runtime exception) if the content pane parameter is null
see
#getContentPane
see
RootPaneContainer#setContentPane
beaninfo
hidden: true description: The client area of the dialog where child components are normally inserted.

        getRootPane().setContentPane(contentPane);
    
public voidsetDefaultCloseOperation(int operation)
Sets the operation that will happen by default when the user initiates a "close" on this dialog. You must specify one of the following choices:

  • DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
  • HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the dialog after invoking any registered WindowListener objects.
  • DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the dialog after invoking any registered WindowListener objects.

The value is set to HIDE_ON_CLOSE by default. Changes to the value of this property cause the firing of a property change event, with property name "defaultCloseOperation".

Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.

param
operation the operation which should be performed when the user closes the dialog
throws
IllegalArgumentException if defaultCloseOperation value isn't one of the above valid values
see
#addWindowListener
see
#getDefaultCloseOperation
see
WindowConstants
beaninfo
preferred: true bound: true enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE description: The dialog's default close operation.

        if (operation != DO_NOTHING_ON_CLOSE &&
            operation != HIDE_ON_CLOSE &&
            operation != DISPOSE_ON_CLOSE) {
            throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE");
        }

        int oldValue = this.defaultCloseOperation;
        this.defaultCloseOperation = operation;
        firePropertyChange("defaultCloseOperation", oldValue, operation);
    
public static voidsetDefaultLookAndFeelDecorated(boolean 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. If defaultLookAndFeelDecorated is true, the current LookAndFeel supports providing window decorations, and the current window manager supports undecorated windows, then newly created JDialogs will have their Window decorations provided by the current LookAndFeel. Otherwise, newly created JDialogs will have their Window decorations provided by the current window manager.

You can get the same effect on a single JDialog by doing the following:

JDialog dialog = new JDialog();
dialog.setUndecorated(true);
dialog.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

param
defaultLookAndFeelDecorated A hint as to whether or not current look and feel should provide window decorations
see
javax.swing.LookAndFeel#getSupportsWindowDecorations
since
1.4

        if (defaultLookAndFeelDecorated) {
            SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.TRUE);
        } else {
            SwingUtilities.appContextPut(defaultLookAndFeelDecoratedKey, Boolean.FALSE);
        }
    
public voidsetGlassPane(java.awt.Component glassPane)
Sets the glassPane property. This method is called by the constructor.

param
glassPane the glassPane object for this dialog
see
#getGlassPane
see
RootPaneContainer#setGlassPane
beaninfo
hidden: true description: A transparent pane used for menu rendering.

        getRootPane().setGlassPane(glassPane);
    
public voidsetJMenuBar(javax.swing.JMenuBar menu)
Sets the menubar for this dialog.

param
menu the menubar being placed in the dialog
see
#getJMenuBar
beaninfo
hidden: true description: The menubar for accessing pulldown menus from this dialog.

        getRootPane().setMenuBar(menu);
    
public voidsetLayeredPane(javax.swing.JLayeredPane layeredPane)
Sets the layeredPane property. This method is called by the constructor.

param
layeredPane the new layeredPane property
exception
java.awt.IllegalComponentStateException (a runtime exception) if the layered pane parameter is null
see
#getLayeredPane
see
RootPaneContainer#setLayeredPane
beaninfo
hidden: true description: The pane which holds the various dialog layers.

        getRootPane().setLayeredPane(layeredPane);
    
public voidsetLayout(java.awt.LayoutManager manager)
Sets the LayoutManager. Overridden to conditionally forward the call to the contentPane. Refer to {@link javax.swing.RootPaneContainer} for more information.

param
manager the LayoutManager
see
#setRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer

        if(isRootPaneCheckingEnabled()) {
            getContentPane().setLayout(manager);
        }
        else {
            super.setLayout(manager);
        }
    
protected voidsetRootPane(javax.swing.JRootPane root)
Sets the rootPane property. This method is called by the constructor.

param
root the rootPane object for this dialog
see
#getRootPane
beaninfo
hidden: true description: the RootPane object for this dialog.

        if(rootPane != null) {
            remove(rootPane);
        }
        rootPane = root;
        if(rootPane != null) {
            boolean checkingEnabled = isRootPaneCheckingEnabled();
            try {
                setRootPaneCheckingEnabled(false);
                add(rootPane, BorderLayout.CENTER);
            }
            finally {
                setRootPaneCheckingEnabled(checkingEnabled);
            }
        }
    
protected voidsetRootPaneCheckingEnabled(boolean enabled)
Sets whether calls to add and setLayout are forwarded to the contentPane.

param
enabled true if add and setLayout are forwarded, false if they should operate directly on the JDialog.
see
#addImpl
see
#setLayout
see
#isRootPaneCheckingEnabled
see
javax.swing.RootPaneContainer
beaninfo
hidden: true description: Whether the add and setLayout methods are forwarded

        rootPaneCheckingEnabled = enabled;
    
public voidsetTransferHandler(javax.swing.TransferHandler newHandler)
Sets the {@code transferHandler} property, which is a mechanism to support transfer of data into this component. Use {@code null} if the component does not support data transfer operations.

If the system property {@code suppressSwingDropSupport} is {@code false} (the default) and the current drop target on this component is either {@code null} or not a user-set drop target, this method will change the drop target as follows: If {@code newHandler} is {@code null} it will clear the drop target. If not {@code null} it will install a new {@code DropTarget}.

Note: When used with {@code JDialog}, {@code TransferHandler} only provides data import capability, as the data export related methods are currently typed to {@code JComponent}.

Please see How to Use Drag and Drop and Data Transfer, a section in The Java Tutorial, for more information.

param
newHandler the new {@code TransferHandler}
see
TransferHandler
see
#getTransferHandler
see
java.awt.Component#setDropTarget
since
1.6
beaninfo
bound: true hidden: true description: Mechanism for transfer of data into the component

        TransferHandler oldHandler = transferHandler;
        transferHandler = newHandler;
        SwingUtilities.installSwingDropTargetAsNecessary(this, transferHandler);
        firePropertyChange("transferHandler", oldHandler, newHandler);
    
public voidupdate(java.awt.Graphics g)
Calls paint(g). This method was overridden to prevent an unnecessary call to clear the background.

param
g the Graphics context in which to paint

        paint(g);