Linked Questions

Popular Questions

Java SWT Draw a Plan

Asked by At

I'm programming my first java App, I wanna create a GUI, which allow to draw different Plan. As close as possible to this representation :

enter image description here

My implementation is based on SWT.

For drawing Nodes and Edges, I used addPaintListener() method from the class Canvas.

But i have following problem, the method paintControl() is called infinitely times, redrawing every time. I ask myself if there is a way to avoid it, or maybe a better way to draw a plan in Java.

Can someone of you suggest me a best way to draw diagram and edge in Java

    Canvas canvas = new Canvas(composite, SWT.ALL);
    canvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {

            Rectangle rect=new Rectangle(0, 0, 60, 30);
            e.gc.drawRectangle(rect);
        }
    });

Related Questions