Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public abstract Class Dialog

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.swt.widgets.DirectoryDialog, org.eclipse.swt.widgets.FileDialog, org.eclipse.swt.widgets.FontDialog, org.eclipse.swt.widgets.MessageBox, org.eclipse.swt.printing.PrintDialog, org.eclipse.swt.widgets.ColorDialog
Imports
org.eclipse.swt.*

This class is the abstract superclass of the classes that represent the built in platform dialogs. A Dialog typically contains other widgets that are not accessible. A Dialog is not a Widget.

This class can also be used as the abstract superclass for user-designed dialogs. Such dialogs usually consist of a Shell with child widgets. The basic template for a user-defined dialog typically looks something like this:


 public class MyDialog extends Dialog {
	Object result;

	public MyDialog (Shell parent, int style) {
		super (parent, style);
	}
	public MyDialog (Shell parent) {
		this (parent, 0); // your default style bits go here (not the Shell's style bits)
	}
	public Object open () {
		Shell parent = getParent();
		Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setText(getText());
		// Your code goes here (widget creation, set result, etc).
		shell.open();
		Display display = parent.getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		return result;
	}
 }
 

Note

The modality styles supported by this class are treated as HINTs, because not all are supported by every subclass on every platform. If a modality style is not supported, it is "upgraded" to a more restrictive modality style that is supported. For example, if PRIMARY_MODAL is not supported by a particular dialog, it would be upgraded to APPLICATION_MODAL. In addition, as is the case for shells, the window manager for the desktop on which the instance is visible has ultimate control over the appearance and behavior of the instance, including its modality.

Styles:
APPLICATION_MODAL, PRIMARY_MODAL, SYSTEM_MODAL, SHEET
Events:
(none)

Note

Only one of the styles APPLICATION_MODAL, PRIMARY_MODAL, and SYSTEM_MODAL may be specified.

See Also
Shell, SWT Example: ControlExample, Sample code and further information

Field Summary

Modifier and TypeField and Description
pack-priv Shell
pack-priv int
pack-priv String

Constructor Summary

AccessConstructor and Description
public
Dialog(Shell
a shell which will be the parent of the new instance
parent
)

Constructs a new instance of this class given only its parent.

public
Dialog(Shell
a shell which will be the parent of the new instance
parent
,
int
the style of dialog to construct
style
)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
checkParent(Shell parent)

Throws an exception if the specified widget can not be used as a parent for the receiver.

pack-priv static int
checkStyle(Shell parent, int style)

protected void
checkSubclass()

Checks that this class can be subclassed.

pack-priv void
error(int
the descriptive error code
code
)

Does whatever dialog specific cleanup is required, and then uses the code in SWTError.error to handle the error.

public Shell

Returns:

the receiver's parent
getParent
()

Returns the receiver's parent, which must be a Shell or null.

public int

Returns:

the style bits
getStyle
()

Returns the receiver's style information.

public String

Returns:

the text
getText
()

Returns the receiver's text, which is the string that the window manager will typically display as the receiver's title.

public void
setText(String
the new text
string
)

Sets the receiver's text, which is the string that the window manager will typically display as the receiver's title, to the argument, which must not be null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

parentback to summary
pack-priv Shell parent
styleback to summary
pack-priv int style
titleback to summary
pack-priv String title

Constructor Detail

Dialogback to summary
public Dialog(Shell parent)

Constructs a new instance of this class given only its parent.

Parameters
parent:Shell

a shell which will be the parent of the new instance

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the parent is null
SWTException:
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
Dialogback to summary
public Dialog(Shell parent, int style)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters
parent:Shell

a shell which will be the parent of the new instance

style:int

the style of dialog to construct

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the parent is null
SWTException:
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
See Also
SWT#PRIMARY_MODAL, SWT#APPLICATION_MODAL, SWT#SYSTEM_MODAL

Method Detail

checkParentback to summary
pack-priv void checkParent(Shell parent)

Throws an exception if the specified widget can not be used as a parent for the receiver.

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the parent is null
  • ERROR_INVALID_ARGUMENT - if the parent is disposed
SWTException:
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
checkStyleback to summary
pack-priv static int checkStyle(Shell parent, int style)
checkSubclassback to summary
protected void checkSubclass()

Checks that this class can be subclassed.

Important Note

See the comment in Widget.checkSubclass().

Exceptions
SWTException:
  • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
See Also
Widget#checkSubclass
errorback to summary
pack-priv void error(int code)

Does whatever dialog specific cleanup is required, and then uses the code in SWTError.error to handle the error.

Parameters
code:int

the descriptive error code

See Also
SWT#error(int)
getParentback to summary
public Shell getParent()

Returns the receiver's parent, which must be a Shell or null.

Returns:Shell

the receiver's parent

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
getStyleback to summary
public int getStyle()

Returns the receiver's style information.

Note that, the value which is returned by this method may not match the value which was provided to the constructor when the receiver was created.

Returns:int

the style bits

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
getTextback to summary
public String getText()

Returns the receiver's text, which is the string that the window manager will typically display as the receiver's title. If the text has not previously been set, returns an empty string.

Returns:String

the text

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
setTextback to summary
public void setText(String string)

Sets the receiver's text, which is the string that the window manager will typically display as the receiver's title, to the argument, which must not be null.

Parameters
string:String

the new text

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the text is null
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver