Working with Shell Styles
Windows
come in all types, shapes, and
sizes. Some have titlebars, some don’t. Some have
minimize, maximize, and close buttons, and some
don’t. You need some way to control the appearance
of windows, and with the SWT Shell
class, you do
that by using a second constructor that enables you to pass a
style—
an integer value the class uses to determine what attributes to show
or hide.
How do I do that?
To specify a
style for a shell, the SWT
provides us with a set of enumerated values encapsulated in another
class called SWT
. The SWT
class is
located in the
org.eclipse.swt
package. For shells, the enumerated
values are BORDER
,
CLOSE
, MIN
,
MAX
, NO_TRIM
,
RESIZE
, and TITLE
. Also, two
convenience
values—SHELL_TRIM
and
DIALOG_TRIM
—combine several of the style attributes
to create two common looks for windows.
The Shell
class
has multiple constructors. You utilized one of those earlier when you
created an instance of your first shell:
Shell s = new Shell(d);
This constructor accepted only an instance of the
Display
class as an argument. To open an instance
of Shell
that accepts a style value, you must
use a different constructor:
Shell(Display display, int style)
As you can see from this constructor’s prototype,
you are permitted to pass in only a single int
value to control all the attributes. This means that
you must have some way to combine the enumerated values in any combination you require. In Java programming, you can combine these values using the ...
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.