Opening True Dialogs
ChildShellExample
demonstrated how to open a child
window within the confines of a parent window, but this is not the
same as opening a true dialog. A dialog window is one that halts
processing of code in the parent window until the user takes some
action in the dialog. In ChildShellExample
, the
parent window code continued to execute even while the child window
was opened. You can see the effect if you execute Example 2-8.
Example 2-8. Demonstrating the effect of opening a child on the parent
import org.eclipse.swt.widgets.*; public class ChildShellExample { Display d = new Display( ); ChildShellExample( ) { Shell s = new Shell(d); s.setSize(500,500); s.open( ); ChildShell cs1 = new ChildShell(s); System.out.println("Execution Continues"); while(!s.isDisposed( )){ if(!d.readAndDispatch( )) d.sleep( ); } d.dispose( ); } }
If you execute this version of ChildShellExample
,
you see that the message is printed to the Console immediately after
the child window is opened. What if you need to wait for the user to
take some action in the child window before knowing how to proceed?
For this, you must use a special form of window known as a
dialog. The SWT provides the capability to work
with dialogs in the form of the
Dialog
class.
How do I do that?
The Dialog
class enables you to create custom
dialogs—those on which you can place any widget you desire. A
dialog is simply another type of shell
, except
that it extends the Dialog
class, which encapsulates some additional ...
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.