is new.
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Window
java.awt.Dialog
javax.swing.JDialog
public class JDialog
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 conveniance 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
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 Frame for more information.
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 TM has been added to the java.beans package. Please see XMLEncoder .
| Nested Class Summary | |
|---|---|
| protected class |
JDialog.AccessibleJDialog
This class implements accessibility support for the JDialog class. |
| Nested classes/interfaces inherited from class java.awt. Dialog |
|---|
Dialog.AccessibleAWTDialog
,
Dialog.ModalExclusionType
,
Dialog.ModalityType
|
| Nested classes/interfaces inherited from class java.awt. Window |
|---|
| Window.AccessibleAWTWindow |
| Nested classes/interfaces inherited from class java.awt. Container |
|---|
| Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt. Component |
|---|
Component.AccessibleAWTComponent
,
Component.BaselineResizeBehavior
,
Component.BltBufferStrategy
,
Component.FlipBufferStrategy
|
| Field Summary | |
|---|---|
| protected AccessibleContext |
accessibleContext
|
| protected JRootPane |
rootPane
|
| protected boolean |
rootPaneCheckingEnabled
If true then calls to add and setLayout will be forwarded to the contentPane. |
Fields inherited from class java.awt.
Dialog
|
|---|
DEFAULT_MODALITY_TYPE
|
| Fields inherited from class java.awt. Component |
|---|
| BOTTOM_ALIGNMENT , CENTER_ALIGNMENT , LEFT_ALIGNMENT , RIGHT_ALIGNMENT , TOP_ALIGNMENT |
| Fields inherited from interface javax.swing. WindowConstants |
|---|
| DISPOSE_ON_CLOSE , DO_NOTHING_ON_CLOSE , EXIT_ON_CLOSE , HIDE_ON_CLOSE |
| Fields inherited from interface java.awt.image. ImageObserver |
|---|
| ABORT , ALLBITS , ERROR , FRAMEBITS , HEIGHT , PROPERTIES , SOMEBITS , WIDTH |
| Constructor Summary | |
|---|---|
|
JDialog
() Creates a
modeless
|
|
|
JDialog
(
Dialog
Creates a
modeless
|
|
|
JDialog
(
Dialog
Creates a
Dialog and modality.
|
|
|
JDialog
(
Dialog
owner,
String
Creates a
modeless
|
|
|
JDialog
(
Dialog
owner,
String
Creates a
title, modality
Dialog.
|
|
|
JDialog
(
Dialog
owner,
String
title, boolean modal,
GraphicsConfiguration
Creates a
modality
and GraphicsConfiguration. |
|
|
JDialog
(
Frame
Creates a
modeless
|
|
|
JDialog
(
Frame
Creates a
Frame, modality and an empty title.
|
|
|
JDialog
(
Frame
owner,
String
Creates a
modeless
|
|
|
JDialog
(
Frame
owner,
String
Creates a
title,
Frame and modality.
|
|
|
JDialog
(
Frame
owner,
String
title, boolean modal,
GraphicsConfiguration
Creates a
modality
and GraphicsConfiguration. |
|
JDialog
(
Window
Creates a modeless dialog with the specified owner Window and an empty title.
|
|
JDialog
(
Window
owner,
Dialog.ModalityType
Creates a dialog with the specified owner Window, modality and an empty title.
|
|
JDialog
(
Window
owner,
String
Creates a modeless dialog with the specified title and owner Window.
|
|
JDialog
(
Window
owner,
String
title,
Dialog.ModalityType
Creates a dialog with the specified title, owner Window and modality.
|
|
JDialog
(
Window
owner,
String
title,
Dialog.ModalityType
modalityType,
GraphicsConfiguration
Creates a dialog with the specified title, owner Window, modality and GraphicsConfiguration.
|
|
| Method Summary | |
|---|---|
| protected void |
addImpl
(
Component
comp,
Object
constraints, int index) Adds the specified child Component. |
| protected JRootPane |
createRootPane
() Called by the constructor methods to create the default rootPane. |
| protected void |
dialogInit
() Called by the constructors to init the JDialog properly. |
| AccessibleContext |
getAccessibleContext
() Gets the AccessibleContext associated with this JDialog. |
| Container |
getContentPane
() Returns the contentPane object for this dialog. |
| int |
getDefaultCloseOperation
() Returns the operation which occurs when the user initiates a "close" on this dialog. |
| Component |
getGlassPane
() Returns the glassPane object for this dialog. |
| JMenuBar |
getJMenuBar
() Returns the menubar set on this dialog. |
| JLayeredPane |
getLayeredPane
() Returns the layeredPane object for this dialog. |
| JRootPane |
getRootPane
() Returns the rootPane object for this dialog. |
TransferHandler
|
getTransferHandler
()
Gets the transferHandler property.
|
| static boolean |
isDefaultLookAndFeelDecorated
() Returns true if newly created JDialogs should have their Window decorations provided by the current look and feel. |
| protected boolean |
isRootPaneCheckingEnabled
() Returns whether calls to add and setLayout are forwarded to the contentPane. |
| protected String |
paramString
() Returns a string representation of this JDialog. |
| protected void |
processWindowEvent
(
WindowEvent
e) Handles window events depending on the state of the defaultCloseOperation property. |
| void |
remove
(
Component
comp) Removes the specified component from the container. |
void
|
repaint
(long time, int x, int y, int width, int height)
Repaints the specified rectangle of this component within time milliseconds.
|
| void |
setContentPane
(
Container
contentPane) Sets the contentPane property. |
| void |
setDefaultCloseOperation
(int operation) Sets the operation
that
|
| static void |
setDefaultLookAndFeelDecorated
(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. |
| void |
setGlassPane
(
Component
glassPane) Sets the glassPane property. |
| void |
setJMenuBar
(
JMenuBar
menu) Sets the menubar for this dialog. |
| void |
setLayeredPane
(
JLayeredPane
layeredPane) Sets the layeredPane property. |
| void |
setLayout
(
LayoutManager
manager) Sets the LayoutManager. |
| protected void |
setRootPane
(
JRootPane
root) Sets the rootPane property. |
| protected void |
setRootPaneCheckingEnabled
(boolean enabled) Sets whether calls to add and setLayout are forwarded to the contentPane. |
void
|
setTransferHandler
(
TransferHandler
Sets the transferHandler property, which is a mechanism to support transfer of data into this component.
|
| void |
update
(
Graphics
g) Calls paint(g). |
| Methods inherited from class java.awt. Dialog |
|---|
addNotify
,
getModalityType
,
getTitle
,
hide
,
isModal
,
isResizable
,
isUndecorated
,
setModal
,
setModalityType
,
setResizable
,
setTitle
,
setUndecorated
,
setVisible
,
show
,
toBack
|
| Methods inherited from class java.lang. Object |
|---|
clone
,
equals
,
finalize
,
getClass
,
hashCode
,
notify
,
notifyAll
,
wait
,
wait
,
wait
|
| Field Detail |
|---|
protected JRootPane rootPane
protected boolean rootPaneCheckingEnabled
protected AccessibleContext accessibleContext
| Constructor Detail |
|---|
public JDialog()
() throwsHeadlessException
modeless
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.
public JDialog(Frameowner)
owner) throwsHeadlessException
modeless
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.
public JDialog(Frame owner, boolean modal)throwsHeadlessException
Frame, modality and an empty title.
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.
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.
public JDialog(Frame owner,
String
title) 
title)
throws 
HeadlessException
modeless
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.
public JDialog(Frame owner,
String title,
boolean modal) 
throws 
HeadlessException
title,
Frame and modality.
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.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
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
Dialog.ModalityType
,
Dialog.ModalityType.MODELESS
,
Dialog.DEFAULT_MODALITY_TYPE
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
public JDialog(Frame owner,
String title,
boolean modal,
GraphicsConfiguration gc)
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.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
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.
Dialog.ModalityType
,
Dialog.ModalityType.MODELESS
,
Dialog.DEFAULT_MODALITY_TYPE
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
public JDialog(Dialogowner)
owner) throwsHeadlessException
modeless
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
owner
or null if this dialog has no owner
public JDialog(Dialog owner, boolean modal)throwsHeadlessException
Dialog and modality.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
owner
or null if this dialog has no owner
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.
Dialog.ModalityType
,
Dialog.ModalityType.MODELESS
,
Dialog.DEFAULT_MODALITY_TYPE
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
public JDialog(Dialog owner,
String
title) 
title)
throws 
HeadlessException
modeless
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
owner
or null if this dialog has no owner
public JDialog(Dialog owner,
String title,
boolean modal) 
throws 
HeadlessException
title, modality
Dialog.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
owner
or null if this dialog has no owner
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
Dialog.ModalityType
,
Dialog.ModalityType.MODELESS
,
Dialog.DEFAULT_MODALITY_TYPE
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
public JDialog(Dialog owner,
String title,
boolean modal,
GraphicsConfiguration
gc) 
gc)
throws 
HeadlessException
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.
owner
Dialog from which the dialog is displayed
or null if this dialog has no owner
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
returns true.
Dialog.ModalityType
Dialog.ModalityType.MODELESS
,
Dialog.DEFAULT_MODALITY_TYPE
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
JDialog
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.
Parameters:
owner - the Window from which the dialog is displayed or null if this dialog has no owner
Throws:
HeadlessException
- when GraphicsEnvironment.isHeadless() returns true
Since:
1.6
See Also:
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
JDialog
public
JDialog
(
Window
owner,
Dialog.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.
Parameters:
owner - the Window from which the dialog is displayed or null if this dialog has no owner
modalityType - specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
Throws:
HeadlessException
- when GraphicsEnvironment.isHeadless() returns true
Since:
1.6
See Also:
Dialog.ModalityType
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
JDialog
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.
Parameters:
owner - the Window from which the dialog is displayed or null if this dialog has no owner
title - the String to display in the dialog's title bar or null if the dialog has no title
Throws:
HeadlessException
- when GraphicsEnvironment.isHeadless() returns true
Since:
1.6
See Also:
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
JDialog
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.
Parameters:
owner - the Window from which the dialog is displayed or null if this dialog has no owner
title - the String to display in the dialog's title bar or null if the dialog has no title
modalityType - specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
Throws:
HeadlessException
- when GraphicsEnvironment.isHeadless() returns true
Since:
1.6
See Also:
Dialog.ModalityType
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
JDialog
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.
Parameters:
owner - the Window from which the dialog is displayed or null if this dialog has no owner
title - the String to display in the dialog's title bar or null if the dialog has no title
modalityType - specifies whether dialog blocks input to other windows when shown. null value and unsupported modality types are equivalent to MODELESS
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 is assumed
Throws:
HeadlessException
- when GraphicsEnvironment.isHeadless() returns true
Since:
1.6
See Also:
Dialog.ModalityType
,
Dialog.setModal(boolean)
,
Dialog.setModalityType(java.awt.Dialog.ModalityType)
,
GraphicsEnvironment.isHeadless()
,
JComponent.getDefaultLocale()
| Method Detail |
|---|
protected void dialogInit()
protected JRootPane createRootPane()
protected void processWindowEvent(WindowEvent e)
public void setDefaultCloseOperation(int operation)
that
You must specify one of the following choices:
(defined in WindowConstants): Don't
anything;
(defined in WindowConstants): Automatically
objects.
(defined in WindowConstants): Automatically
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.
Parameters:
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
,
WindowConstants
public int getDefaultCloseOperation()
setTransferHandler
public void
setTransferHandler
(
TransferHandler
newHandler)
Sets the transferHandler property, which is a mechanism to support transfer of data into this component. Use null if the component does not support data transfer operations.
If the system property suppressSwingDropSupport is false (the default) and the current drop target on this component is either null or not a user-set drop target, this method will change the drop target as follows: If newHandler is null it will clear the drop target. If not null it will install a new DropTarget.
Note: When used with JDialog, TransferHandler only provides data import capability, as the data export related methods are currently typed to JComponent.
Please see
How to Use Drag and Drop and Data Transfer
, a section in The Java Tutorial, for more information.
Parameters:
newHandler - the new TransferHandler
Since:
1.6
See Also:
TransferHandler
,
getTransferHandler()
,
Component.setDropTarget(java.awt.dnd.DropTarget)
getTransferHandler
public
TransferHandler
getTransferHandler
()
Gets the transferHandler property.
Returns:
the value of the transferHandler property
Since:
1.6
See Also:
TransferHandler
,
setTransferHandler(javax.swing.TransferHandler)
public void update(Graphics g)
public void setJMenuBar(JMenuBar menu)
public JMenuBar getJMenuBar()
protected boolean isRootPaneCheckingEnabled()
protected void setRootPaneCheckingEnabled(boolean enabled)
protected void addImpl(Component comp,
Object constraints,
int index)
forward
public void remove(Component comp)
public void setLayout(LayoutManager manager)
public JRootPane getRootPane()
protected void setRootPane(JRootPane root)
public Container getContentPane()
public void setContentPane(Container contentPane)
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.
public JLayeredPane getLayeredPane()
public void setLayeredPane(JLayeredPane layeredPane)
public Component getGlassPane()
public void setGlassPane(Component glassPane)
repaint
public void
repaint
(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.
Overrides:
repaint
in class
Component
Parameters:
time - maximum time in milliseconds before update
x - the
x
coordinate
y - the
y
coordinate
width - the width
height - the height
Since:
1.6
See Also:
RepaintManager
public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
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);
public static boolean isDefaultLookAndFeelDecorated()
protected String paramString()
public AccessibleContext getAccessibleContext()