Chapter 17. SWT Standard Dialogs
As GUI users, you are no doubt familiar with some of the complex windows used for common everyday operations such as opening files, choosing fonts or colors, and selecting which printer gets the output. If these windows had to be coded from scratch, the cost in development time would be high.
Recognizing this, the SWT provides us with predeveloped versions of these windows—known collectively as the Standard Dialogs. Six such dialogs are provided for your use:
MessageBox
DirectoryDialog
FileDialog
ColorDialog
FontDialog
PrintDialog
Each of these is represented by a single class that is located in the
org.eclipse.swt.widgets
package (except for
PrintDialog
, which resides in
org.eclipse.swt.printing
). The sections that
follow discuss each in turn, showing how to incorporate them into
your applications.
Using the SWT MessageBox Class
MessageBox
is
used to display some information to the user, such as an error
condition, or to obtain simple input from the user, or both. The
message box is displayed with a series of buttons, such as Yes, No,
or Cancel. The program waits until the user makes a selection, then
branches execution depending upon which selection was made.
How do I do that?
Perhaps the best example of using a
MessageBox
is seen when the user attempts to close
an application by selecting File Exit from the
program’s menu. Often a message box will appear
asking the user for confirmation before actually exiting. Example 17-1 demonstrates ...
Get SWT: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.