Creating a Shell Styles Example
To demonstrate
how different
style combinations affect the appearance and functionality of a
shell, create a modification to your earlier
SimpleShell
example and pass the
Shell
constructor a different combination of
styles.
How do I do that?
Example 2-3 is similar to the earlier
SimpleShell
class, modified to specify a window
that has a close button, has no min or max button, and is resizable.
Example 2-3. Setting the shell styles
import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class ShellStylesExample { ShellStyles( ) { Display d = new Display( ); Shell s = new Shell(d, SWT.CLOSE | SWT.RESIZE); s.setSize(300,300); s.open( ); while(!s.isDisposed( )){ if(!d.readAndDispatch( )) d.sleep( ); } d.dispose( ); } }
The only difference between this class and the
SimpleShell
example is that the second constructor
form is used and the style parameter is used to specify the desired
window attributes.
Next, modify the Runner
program to load up an instance
of ShellStylesExample
, as demonstrated in
Example 2-4
.
Note
Or you can create a Run Configuration for the new class.
Example 2-4. Revised Runner class
public class Runner { public static void main(String[] args){ ShellStylesExample sse = new ShellStylesExample ( ); } }
Tip
This is the last time I will show you how to modify the
Runner
class. You should have the idea down pat by
now.
The result of ShellStylesExample
is as shown in
Figure 2-3. You see only a close button displayed on the titlebar and ...
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.