List of usage examples for org.eclipse.swt.widgets Display getBounds
@Override
public Rectangle getBounds()
From source file:DisplayBounds.java
public static void main(String[] args) { Display display = new Display(); System.out.println(// w ww . ja v a 2s . c o m "Display Bounds=" + display.getBounds() + " Display ClientArea=" + display.getClientArea()); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet215.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 215"); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.addListener(SWT.Selection, event -> { /* Take the screen shot */ GC gc = new GC(display); final Image image = new Image(display, display.getBounds()); gc.copyArea(image, 0, 0);/*from w ww . java 2 s . c om*/ gc.dispose(); Shell popup = new Shell(shell, SWT.SHELL_TRIM); popup.setLayout(new FillLayout()); popup.setText("Image"); popup.setBounds(50, 50, 200, 200); popup.addListener(SWT.Close, e -> image.dispose()); ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL); Canvas canvas = new Canvas(sc, SWT.NONE); sc.setContent(canvas); canvas.setBounds(display.getBounds()); canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0)); popup.open(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScreenShotWithGC.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { /* Take the screen shot */ GC gc = new GC(display); final Image image = new Image(display, display.getBounds()); gc.copyArea(image, 0, 0);//from w w w. j a v a 2s. c o m gc.dispose(); Shell popup = new Shell(shell, SWT.SHELL_TRIM); popup.setLayout(new FillLayout()); popup.setText("Image"); popup.setBounds(50, 50, 200, 200); popup.addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { image.dispose(); } }); ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL); Canvas canvas = new Canvas(sc, SWT.NONE); sc.setContent(canvas); canvas.setBounds(display.getBounds()); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); popup.open(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet104.java
public static void main(String[] args) { final Display display = new Display(); final int[] count = new int[] { 4 }; final Image image = new Image(display, 300, 300); final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]);/*from www . j a v a 2 s . co m*/ Label label = new Label(splash, SWT.NONE); label.setImage(image); FormLayout layout = new FormLayout(); splash.setLayout(layout); FormData labelData = new FormData(); labelData.right = new FormAttachment(100, 0); labelData.bottom = new FormAttachment(100, 0); label.setLayoutData(labelData); FormData progressData = new FormData(); progressData.left = new FormAttachment(0, 5); progressData.right = new FormAttachment(100, -5); progressData.bottom = new FormAttachment(100, -5); bar.setLayoutData(progressData); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); display.asyncExec(new Runnable() { public void run() { Shell[] shells = new Shell[count[0]]; for (int i = 0; i < count[0]; i++) { shells[i] = new Shell(display); shells[i].setSize(300, 300); shells[i].addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { --count[0]; } }); bar.setSelection(i + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i = 0; i < count[0]; i++) { shells[i].open(); } } }); while (count[0] != 0) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet104.java
public static void main(String[] args) { final Display display = new Display(); final int[] count = new int[] { 4 }; final Image image = new Image(display, 300, 300); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); gc.fillRectangle(image.getBounds()); gc.drawText("Splash Screen", 10, 10); gc.dispose();/* w ww .j av a 2 s . c o m*/ final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]); Label label = new Label(splash, SWT.NONE); label.setImage(image); FormLayout layout = new FormLayout(); splash.setLayout(layout); FormData labelData = new FormData(); labelData.right = new FormAttachment(100, 0); labelData.bottom = new FormAttachment(100, 0); label.setLayoutData(labelData); FormData progressData = new FormData(); progressData.left = new FormAttachment(0, 5); progressData.right = new FormAttachment(100, -5); progressData.bottom = new FormAttachment(100, -5); bar.setLayoutData(progressData); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); display.asyncExec(() -> { Shell[] shells = new Shell[count[0]]; for (int i1 = 0; i1 < count[0]; i1++) { shells[i1] = new Shell(display); shells[i1].setSize(300, 300); shells[i1].addListener(SWT.Close, e -> --count[0]); bar.setSelection(i1 + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i2 = 0; i2 < count[0]; i2++) { shells[i2].setText("SWT Snippet 104 - " + (i2 + 1)); shells[i2].open(); } }); while (count[0] != 0) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SplashScreenCreate.java
public static void main(String[] args) { final Display display = new Display(); final int[] count = new int[] { 4 }; final Image image = new Image(display, 300, 300); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); gc.fillRectangle(image.getBounds()); gc.drawText("Splash Screen", 10, 10); gc.dispose();/*w ww .java2s . c o m*/ final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]); Label label = new Label(splash, SWT.NONE); label.setImage(image); FormLayout layout = new FormLayout(); splash.setLayout(layout); FormData labelData = new FormData(); labelData.right = new FormAttachment(100, 0); labelData.bottom = new FormAttachment(100, 0); label.setLayoutData(labelData); FormData progressData = new FormData(); progressData.left = new FormAttachment(0, 5); progressData.right = new FormAttachment(100, -5); progressData.bottom = new FormAttachment(100, -5); bar.setLayoutData(progressData); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); display.asyncExec(new Runnable() { public void run() { Shell[] shells = new Shell[count[0]]; for (int i = 0; i < count[0]; i++) { shells[i] = new Shell(display); shells[i].setSize(300, 300); shells[i].addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { --count[0]; } }); bar.setSelection(i + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i = 0; i < count[0]; i++) { shells[i].open(); } } }); while (count[0] != 0) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:PaintExample.java
/** * Sets the size of the shell to it's "packed" size, * unless that makes it bigger than the display, * in which case set it to 9/10 of display size. *//* w w w . ja v a 2 s. c om*/ private static void setShellSize(Display display, Shell shell) { Rectangle bounds = display.getBounds(); Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); if (size.x > bounds.width) size.x = bounds.width * 9 / 10; if (size.y > bounds.height) size.y = bounds.height * 9 / 10; shell.setSize(size); }
From source file:CustomControlExample.java
/** * Sets the size of the shell to it's "packed" size, unless that makes it * bigger than the display, in which case set it to 9/10 of display size. */// w ww.jav a 2s .co m static void setShellSize(Display display, Shell shell) { Rectangle bounds = display.getBounds(); Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); if (size.x > bounds.width) size.x = bounds.width * 9 / 10; if (size.y > bounds.height) size.y = bounds.height * 9 / 10; shell.setSize(size); }