Using the Group Class
The SWT Group
class extends the
Composite
class and provides some additional
functionality related primarily to the appearance of the group.
Group
permits you to add a text label as a prompt
to the user of group contents and to change the border style of the
resulting object, yielding more of a visual indication to the user
that the widgets are part of a functional area of the application.
Because the Group
class cannot be subclassed, it
must be used in a manner similar to
Shell
—you create an instance of
Group
within another container class (such as
Composite
) and then add widgets to that instance.
How do I do that?
The task of creating a Group
is
very similar to the task of creating a Shell
.
First, create a Composite
that will serve as the
container for the Group
, as shown in Example 10-4.
Example 10-4. Using a Group
import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.*; import org.eclipse.swt.SWT; public class GroupExample extends Composite { final Button b1; final Button b2; final Button b3; public GroupExample(Composite c, int style) { super(c, SWT.NO_BACKGROUND ); this.setSize(110, 75); this.setLayout(new FillLayout( )); final Group g = new Group(this, style); g.setSize(110, 75); g.setText("Options Group"); b1 = new Button(g, SWT.RADIO); b1.setBounds(10,20,75, 15); b1.setText("Option One"); b2 = new Button(g, SWT.RADIO); b2.setBounds(10,35,75, 15); b2.setText("Option Two"); b3 = new Button(g, SWT.RADIO); b3.setBounds(10,50,80, 15);
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.