List of usage examples for org.eclipse.swt.widgets Canvas setSize
public void setSize(int width, int height)
From source file:DrawExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Drawing Example"); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.setSize(150, 150); canvas.setLocation(20, 20);//www . j a va 2 s. com shell.open(); shell.setSize(200, 220); GC gc = new GC(canvas); gc.drawRectangle(10, 10, 40, 45); gc.drawOval(65, 10, 30, 35); gc.drawLine(130, 10, 90, 80); gc.drawPolygon(new int[] { 20, 70, 45, 90, 70, 70 }); gc.drawPolyline(new int[] { 10, 120, 70, 100, 100, 130, 130, 75 }); gc.dispose(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CanvasKeyEvent.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final Canvas canvas = new Canvas(shell, SWT.NULL); canvas.setSize(500, 500); canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); canvas.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { GC gc = new GC(canvas); Rectangle rect = canvas.getClientArea(); gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); Font font = new Font(display, "Arial", 32, SWT.BOLD); gc.setFont(font);/*w ww . ja v a2 s .c om*/ gc.drawString("" + e.character, 15, 10); gc.dispose(); font.dispose(); } public void keyReleased(KeyEvent e) { } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:FocusTraversal.java
private void init() { shell.setLayout(new RowLayout()); Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setLayout(new RowLayout()); composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); Button button1 = new Button(composite1, SWT.PUSH); button1.setText("Button1"); List list = new List(composite1, SWT.MULTI | SWT.BORDER); list.setItems(new String[] { "Item-1", "Item-2", "Item-3" }); Button radioButton1 = new Button(composite1, SWT.RADIO); radioButton1.setText("radio-1"); Button radioButton2 = new Button(composite1, SWT.RADIO); radioButton2.setText("radio-2"); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new RowLayout()); composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); Button button2 = new Button(composite2, SWT.PUSH); button2.setText("Button2"); final Canvas canvas = new Canvas(composite2, SWT.NULL); canvas.setSize(50, 50); canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0);//from www .j a va 2s .c o m canvas.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { GC gc = new GC(canvas); // Erase background first. Rectangle rect = canvas.getClientArea(); gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); Font font = new Font(display, "Arial", 32, SWT.BOLD); gc.setFont(font); gc.drawString("" + e.character, 15, 10); gc.dispose(); font.dispose(); } public void keyReleased(KeyEvent e) { } }); canvas.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) e.doit = true; } }); composite1.setTabList(new Control[] { button1, list }); composite2.setTabList(new Control[] { button2, canvas, combo }); shell.setTabList(new Control[] { composite2, composite1 }); }