Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » elementary draw2d program doesn't work
elementary draw2d program doesn't work [message #643944] Wed, 08 December 2010 18:40 Go to next message
Carlo Salinari is currently offline Carlo SalinariFriend
Messages: 66
Registered: October 2010
Member
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 23:03 Go to previous message
Carlo Salinari is currently offline Carlo SalinariFriend
Messages: 66
Registered: October 2010
Member
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();
>
> }
>
> }
Previous Topic:Unable to run org.eclipse.gef.examples.ediagram
Next Topic:Problem with TextFlow clipping text on Zoom
Goto Forum:
  


Current Time: Fri Dec 19 15:53:28 GMT 2014

Powered by FUDForum. Page generated in 0.10205 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software