| Example 2 - Layout Managers | |
|
In this example, a panel is created with a FlowLayout for its layout manager. A flow layout positions children left-to-right in rows going from top-to-bottom. The children are sized according to their preferred size. |
|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.draw2d.*;
import org.eclipse.swt.SWT;
import org.eclipse.draw2d.geometry.*;
public class Demo2 {
public static void main(String args[]){
Shell shell = new Shell();
shell.open();
shell.setText("Draw2d");
LightweightSystem lws = new LightweightSystem(shell);
IFigure panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);
Clickable button = new Button("Click me");
Clickable checkbox = new CheckBox("Check box");
Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);
Shape rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.lightBlue);
panel.add(button);
panel.add(checkbox);
panel.add(ellipse);
panel.add(rectangle);
Display display = Display.getDefault();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
}
}
|