Example usage for org.eclipse.swt.widgets Canvas Canvas

List of usage examples for org.eclipse.swt.widgets Canvas Canvas

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Canvas Canvas.

Prototype

public Canvas(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:CanvasTranverseEvent.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    final Canvas c = new Canvas(shell, SWT.BORDER);
    c.setBounds(10, 50, 100, 32);/*  w  w w  .j  a va2  s .  com*/
    c.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event e) {
            switch (e.detail) {
            /* Do tab group traversal */
            case SWT.TRAVERSE_ESCAPE:
                System.out.println("SWT.TRAVERSE_ESCAPE");
                break;
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_TAB_NEXT:
                System.out.println("SWT.TRAVERSE_TAB_NEXT");
                break;
            case SWT.TRAVERSE_TAB_PREVIOUS:
            case SWT.TRAVERSE_PAGE_NEXT:
            case SWT.TRAVERSE_PAGE_PREVIOUS:
                e.doit = true;
                break;
            }
        }
    });

    Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t.setBounds(10, 85, 100, 32);

    c.setFocus();
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:DrawTextSWT.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawString("www.java2s.com", 5, 5);
        }/*from w  ww .  ja  v a  2s . co  m*/
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:DrawOval.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawOval(200, 100, 500, 400);
        }/*www  .  j av a  2s  .  c o m*/
    });

    canvas.redraw();

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:DrawArcSWT.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK));
            e.gc.fillArc(200, 100, 500, 400, 30, 40);
        }// www . ja  v  a  2 s . co  m
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:FillRectangle.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.fillRectangle(30, 40, 400, 200);
        }/*from  www.  j a v  a  2 s. c  om*/
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:GCFromEvent.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.drawFocus(5, 5, 200, 10);
            e.gc.drawText("You can draw text directly on a canvas", 60, 60);
        }//from  w w w  .  j  a  va  2  s  .  c  om
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);//from  w w  w  .  j a va 2s.com

    shell.setLayout(new FillLayout());

    Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new ArcExamplePaintListener());

    shell.open();
    while (!shell.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:CanvasRepaint.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawRoundRectangle(10, 10, 200, 200, 30, 30);
        }/*from   w w  w  . j av a2 s . co m*/
    });

    canvas.redraw();

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);//from w ww  .  j  a  v  a 2s .  com

    shell.setLayout(new FillLayout());

    Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new ArcExamplePaintListener());
    drawingCanvas.redraw();

    shell.open();
    while (!shell.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:DrawRoundRectangle.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Canvas Example");
    shell.setLayout(new FillLayout());

    Canvas canvas = new Canvas(shell, SWT.NONE);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawRoundRectangle(10, 10, 200, 200, 30, 30);
        }//from w  w  w  .ja  v  a2  s. c o m
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}