Chapter 10. SWT Composites and Groups
Until now, all examples that have been created have included widgets
that were added directly to an instance of Shell
.
This approach works well for simple interfaces, but more complex
designs require the use of a different layout manager for different parts of
the window. For example, you might want a row of buttons at the
bottom of a window—a perfect situation for
RowLayout
—while data is displayed above the
buttons in the form of a grid, a perfect situation for
GridLayout
.
The SWT provides for these situations with two additional classes
that can act as containers for widgets:
Composite
and Group
. These
classes are located in the
org.eclipse.swt.widgets
package.
Before you learn how to use the Composite
and
Group
classes together with layouts to build
complex user interfaces for use in your applications, you should
first gain a basic understanding of the Composite
and Group
classes themselves. Since
Group
is a subclass of
Composite
, it makes sense to begin this discussion
by covering the Composite
class.
Composite
objects are created simply to contain
other widgets. Composite
is an ancestor of every
SWT class to which you can add widgets, including
Shell
. For that reason, you can think of a
Composite
as being simply the working area of a
Shell
, without the styles associated with the
aspects of Shell
that make windows—the
titlebar, control menu, etc.
Subclassing the Composite Class
One major
difference between the
Composite
and Shell
classes ...
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.