elementary draw2d program doesn't work [message #643944] |
Wed, 08 December 2010 13:40  |
Eclipse User |
|
|
|
Hi,
I'm trying to visualize a rectangle with draw2d. Can you tell me why
this isn't working?
package test;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test extends Shell {
public static void main(String args[]) {
Display d = new Display();
Shell shell = new Shell(d);
Canvas canvas = new Canvas(shell, SWT.NONE);
LightweightSystem lws = new LightweightSystem(canvas);
IFigure contents = new Figure();
contents.setLayoutManager(new XYLayout());
IFigure figure = new RectangleFigure();
figure.setForegroundColor(ColorConstants.cyan);
contents.add(figure, new Rectangle(100, 100, 200, 300));
lws.setContents(contents);
shell.setText("draw2d");
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
}
}
|
|
|
Re: elementary draw2d program doesn't work [message #643987 is a reply to message #643944] |
Wed, 08 December 2010 18:03  |
Eclipse User |
|
|
|
I found the solution.
I had to add:
shell.setLayout(new FillLayout());
On 12/8/2010 7:40 PM, Carlo Salinari wrote:
> Hi,
> I'm trying to visualize a rectangle with draw2d. Can you tell me why
> this isn't working?
>
> package test;
>
> import org.eclipse.draw2d.ColorConstants;
> import org.eclipse.draw2d.Figure;
> import org.eclipse.draw2d.IFigure;
> import org.eclipse.draw2d.LightweightSystem;
> import org.eclipse.draw2d.RectangleFigure;
> import org.eclipse.draw2d.XYLayout;
> import org.eclipse.draw2d.geometry.Rectangle;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Canvas;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class Test extends Shell {
>
> public static void main(String args[]) {
> Display d = new Display();
> Shell shell = new Shell(d);
>
> Canvas canvas = new Canvas(shell, SWT.NONE);
> LightweightSystem lws = new LightweightSystem(canvas);
>
> IFigure contents = new Figure();
> contents.setLayoutManager(new XYLayout());
>
> IFigure figure = new RectangleFigure();
> figure.setForegroundColor(ColorConstants.cyan);
>
> contents.add(figure, new Rectangle(100, 100, 200, 300));
>
> lws.setContents(contents);
>
> shell.setText("draw2d");
> shell.open();
> while (!shell.isDisposed())
> while (!d.readAndDispatch())
> d.sleep();
>
> }
>
> }
|
|
|
Powered by
FUDForum. Page generated in 0.03199 seconds