List of usage examples for org.eclipse.swt.widgets Button setSize
public void setSize(int width, int height)
From source file:ScollCompositeControl.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is // resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400); c1.setContent(b1);/*w w w . jav a 2s. c o m*/ shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MouseEventPost.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final Button button = new Button(shell, SWT.NONE); button.setSize(100, 100); button.setText("Click"); shell.pack();/* w w w . ja v a2 s . co m*/ shell.open(); button.addListener(SWT.MouseDown, new Listener() { public void handleEvent(Event e) { System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")"); } }); final Point pt = display.map(shell, null, 50, 50); new Thread() { Event event; public void run() { try { Thread.sleep(300); } catch (InterruptedException e) { } event = new Event(); event.type = SWT.MouseMove; event.x = pt.x; event.y = pt.y; display.post(event); try { Thread.sleep(300); } catch (InterruptedException e) { } } }.start(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet142.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final Button button = new Button(shell, SWT.NONE); button.setSize(100, 100); button.setText("Click"); shell.pack();//from w ww . jav a 2 s . c o m shell.open(); button.addListener(SWT.MouseDown, new Listener() { public void handleEvent(Event e) { System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")"); } }); final Point pt = display.map(shell, null, 50, 50); new Thread() { Event event; public void run() { try { Thread.sleep(300); } catch (InterruptedException e) { } event = new Event(); event.type = SWT.MouseMove; event.x = pt.x; event.y = pt.y; display.post(event); try { Thread.sleep(300); } catch (InterruptedException e) { } event.type = SWT.MouseDown; event.button = 1; display.post(event); try { Thread.sleep(300); } catch (InterruptedException e) { } event.type = SWT.MouseUp; display.post(event); } }.start(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet5.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is // resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400); c1.setContent(b1);/*from w w w . j a va2 s . c o m*/ // this button has a minimum size of 400 x 400. If the window is resized // to be big // enough to show more than 400 x 400, the button will grow in size. If // the window // is made too small to show 400 x 400, scrollbars will appear. ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b2 = new Button(c2, SWT.PUSH); b2.setText("expanding button"); c2.setContent(b2); c2.setExpandHorizontal(true); c2.setExpandVertical(true); c2.setMinWidth(400); c2.setMinHeight(400); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet142.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 142"); final Button button = new Button(shell, SWT.NONE); button.setSize(100, 100); button.setText("Click"); shell.pack();/*from w w w .j a v a2 s .c o m*/ shell.open(); button.addListener(SWT.MouseDown, e -> System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")")); final Point pt = display.map(shell, null, 50, 50); new Thread() { Event event; @Override public void run() { try { Thread.sleep(300); } catch (InterruptedException e) { } event = new Event(); event.type = SWT.MouseMove; event.x = pt.x; event.y = pt.y; display.post(event); try { Thread.sleep(300); } catch (InterruptedException e) { } event.type = SWT.MouseDown; event.button = 1; display.post(event); try { Thread.sleep(300); } catch (InterruptedException e) { } event.type = SWT.MouseUp; display.post(event); } }.start(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet5.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 5"); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400); c1.setContent(b1);/*from ww w .j a v a 2 s .c om*/ // this button has a minimum size of 400 x 400. If the window is resized to be big // enough to show more than 400 x 400, the button will grow in size. If the window // is made too small to show 400 x 400, scrollbars will appear. ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b2 = new Button(c2, SWT.PUSH); b2.setText("expanding button"); c2.setContent(b2); c2.setExpandHorizontal(true); c2.setExpandVertical(true); c2.setMinSize(400, 400); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet70.java
public static void main(String[] args) { Display display = new Display(); Color red = display.getSystemColor(SWT.COLOR_RED); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); Image image = new Image(display, 20, 20); GC gc = new GC(image); gc.setBackground(red);// ww w .ja v a 2 s . c o m gc.fillRectangle(5, 5, 10, 10); gc.dispose(); ImageData imageData = image.getImageData(); PaletteData palette = new PaletteData(new RGB(0, 0, 0), new RGB(0xFF, 0xFF, 0xFF)); ImageData maskData = new ImageData(20, 20, 1, palette); Image mask = new Image(display, maskData); gc = new GC(mask); gc.setBackground(black); gc.fillRectangle(0, 0, 20, 20); gc.setBackground(white); gc.fillRectangle(5, 5, 10, 10); gc.dispose(); maskData = mask.getImageData(); Image icon = new Image(display, imageData, maskData); Shell shell = new Shell(display); shell.setText("Snippet 70"); Button button = new Button(shell, SWT.PUSH); button.setImage(icon); button.setSize(60, 60); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } icon.dispose(); image.dispose(); mask.dispose(); display.dispose(); }
From source file:IconInMemory.java
public static void main(String[] args) { Display display = new Display(); Color red = display.getSystemColor(SWT.COLOR_RED); Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); Image image = new Image(display, 20, 20); GC gc = new GC(image); gc.setBackground(red);// ww w.j a v a 2 s .c om gc.fillRectangle(5, 5, 10, 10); gc.dispose(); ImageData imageData = image.getImageData(); PaletteData palette = new PaletteData(new RGB[] { new RGB(0, 0, 0), new RGB(0xFF, 0xFF, 0xFF), }); ImageData maskData = new ImageData(20, 20, 1, palette); Image mask = new Image(display, maskData); gc = new GC(mask); gc.setBackground(black); gc.fillRectangle(0, 0, 20, 20); gc.setBackground(white); gc.fillRectangle(5, 5, 10, 10); gc.dispose(); maskData = mask.getImageData(); Image icon = new Image(display, imageData, maskData); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); button.setImage(icon); button.setSize(60, 60); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } icon.dispose(); image.dispose(); mask.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet167.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 167"); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300); sc1.setContent(button1);//from w ww . j ava 2 s . c om final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = widgetSelectedAdapter(e -> { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); }); SelectionListener listener2 = widgetSelectedAdapter(e -> { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); }); vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollBarSelectionListener.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300); sc1.setContent(button1);//w w w . ja va2 s .c o m final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); } }; SelectionListener listener2 = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); } }; vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }