Java Tutorial/SWT/Group
Содержание
Add image to Group
<source lang="java">
import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; public class GroupImageAdding {
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Group group = new Group(shell, SWT.NONE); group.setLayout(new FillLayout()); group.setText("a square"); Canvas canvas = new Canvas(group, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(new Image(display, "yourFile.gif"), 0, 0); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
}</source>
Add Radio Buttons to a Group
<source lang="java">
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; public class GroupWithRadioButtons {
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout());
// Create the first Group Group group1 = new Group(shell, SWT.SHADOW_IN); group1.setText("Who"s your favorite?"); group1.setLayout(new RowLayout(SWT.VERTICAL)); new Button(group1, SWT.RADIO).setText("A"); new Button(group1, SWT.RADIO).setText("B"); new Button(group1, SWT.RADIO).setText("C"); new Button(group1, SWT.RADIO).setText("D"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
}</source>
Create a Group without grouping Radio Buttons (SWT.NO_RADIO_GROUP)
<source lang="java">
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; public class GroupWithoutGroupingRadioButtons {
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout());
// Create the second Group Group group2 = new Group(shell, SWT.NO_RADIO_GROUP); group2.setText("Who"s your favorite?"); group2.setLayout(new RowLayout(SWT.VERTICAL)); new Button(group2, SWT.RADIO).setText("A"); new Button(group2, SWT.RADIO).setText("B"); new Button(group2, SWT.RADIO).setText("C"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
}</source>
Create Shadow in Group
<source lang="java">
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; public class GroupShadowCreate {
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout());
// Create the first Group Group group1 = new Group(shell, SWT.SHADOW_IN); group1.setText("Who"s your favorite?"); group1.setLayout(new RowLayout(SWT.VERTICAL)); new Button(group1, SWT.RADIO).setText("A"); new Button(group1, SWT.RADIO).setText("B"); new Button(group1, SWT.RADIO).setText("C"); new Button(group1, SWT.RADIO).setText("D"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
}</source>
Introducing Group
- Provide visual organization and structure.
- A Group can display some text along its top, specified by the setText() method.
- A Group derives from Composite, and it can contain other widgets.
Group Styles:
StyleDescriptionSWT.SHADOW_ETCHED_INCreates a Group with the "etched in" shadow style.SWT.SHADOW_ETCHED_OUTCreates a Group with the "etched out" shadow style.SWT.SHADOW_INCreates a Group with the "in" shadow style, which isn"t necessarily popular.SWT.SHADOW_OUTCreates a Group with the "out" shadow style.SWT.SHADOW_NONECreates a Group with no shadow style.SWT.NO_RADIO_GROUPCreate a Group without grouping radio button