Java Tutorial/SWT/Group — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:19, 31 мая 2010
Содержание
Add image to Group
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();
}
}
Add Radio Buttons to a Group
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();
}
}
Create a Group without grouping Radio Buttons (SWT.NO_RADIO_GROUP)
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();
}
}
Create Shadow in Group
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();
}
}
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