Library tutorials & articles
SWT and JFace, Part 1: A gentle introduction
- Introduction
- Basic Controls
- Composites
- Layout managers
Composites
So far, we have been talking about individual controls. In most GUIs, multiple controls are grouped together to provide a rich user experience. In SWT, this grouping is implemented by using the Composite class.
Composites can be nested to any level, and can mix and match controls and composites as children. This can greatly reduce GUI development complexity and create opportunities for GUI code reuse (by encapsulating the inner GUI). Composites can have borders and be easily distinguished visually or can be borderless and seamlessly integrate into even larger groups.
Listing 6 creates a bordered composite.
Listing 6. Create a bordered composite
import org.eclipse.swt.widgets.*;
:
Composite parent = ...;
:
Composite border = new Composite(parent, SWT.BORDER);
In addition to a border, the Group composite sub-class supports a title. Groups are often used to contain radio-type buttons as they define the set of exclusive buttons.
Listing 7 creates a bordered group.
Listing 7. Create a bordered group
import org.eclipse.swt.widgets.*;
:
Composite parent = ...;
:
Group border = new Group(parent, SWT.SHADOW_OUT);
border.setText("Group Description");
Shells
A shell is a top-level composite (frame or window) that may have no parent composite; instead, it has a Display as a parent, often set by default. Shells come in many styles, but the most popular are SWT.SHELL_TRIM or SWT.DIALOG_TRIM.
Shells may be modal or modeless. Modal shells, which are most often
used for dialogs, prevent the parent GUI (if any) from proceeding until
the child shell is closed.
Listing 8 creates a top-level nonmodal shell in frame style.
Listing 8. Create a top-level shell
import org.eclipse.swt.widgets.*;
:
Shell frame = new Shell(SWT.SHELL_TRIM);
:
Shells can have child shells. These are independent desktop windows associated with the parent shell (i.e., if the parent is closed, all of its children will also be closed).
Listing 9 creates a child shell in dialog style.
Listing 9. Create a dialog shell
:
Shell dialog = new Shell(frame, SWT.DIALOG_TRIM);
:
See Figure 4 shell with SWT.SHELL_TRIM and Figure 5 shell with SWT.DIALOG_TRIM to see how these values affect the shell trim.
Figure 4. Shell with SWT.SHELL_TRIM
Figure 5. Shell with SWT.DIALOG_TRIM
Related articles
Related discussion
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Export to excel
by thunderbird (2 replies)
-
org.objectweb.asm.ClassVisitor.visit(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)
by mohu (1 replies)
-
Is it possible to send SMS using PHP or java or VB,j2ee?
by shwetak (1 replies)
-
Bangalore---Java-J2EE Team lead/Tech Lead/Project Lead
by muruganbala_mca (1 replies)
Related podcasts
-
WebWork
During this talk you'll receive an update on WebWork. WebWork is a Java web-application development framework. It is built specifically with developer productivity and code simplicity in mind, providing robust support for building reusable UI templates, such as form controls, UI themes, inter...
Events coming up
-
Dec
15
Portland Java User Group
Portland, United States
This month's topic: TBD----------PJUG meetings start with eat+meet+greet time (pizza and beverages are provided), followed by the featured speaker, then some time for Q&A, discussion, and sometimes a drawing to give away swag. :)It is...
This thread is for discussions of SWT and JFace, Part 1: A gentle introduction.