List of usage examples for org.eclipse.swt.widgets Button getBounds
public Rectangle getBounds()
From source file:WidgetSizeCompute.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Button button = new Button(shell, SWT.PUSH | SWT.LEFT); button.setText("Button"); System.out.println("Bounds: " + button.getBounds()); System.out.println("computeSize: " + button.computeSize(100, SWT.DEFAULT)); System.out.println("computeSize: " + button.computeSize(40, SWT.DEFAULT)); System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, 100)); System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, 20)); System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, 15)); System.out.println("computeSize: " + button.computeSize(100, 200)); System.out.println("computeSize: " + button.computeSize(SWT.DEFAULT, SWT.DEFAULT)); shell.open();// w w w . j a va 2s . c om while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:ControlSizeLocation.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.PUSH); shell.setSize(260, 120);//ww w .jav a2 s .com shell.open(); System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:ControlBounds.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); button.setBounds(20, 20, 200, 20);// ww w . j av a2 s . c o m shell.setSize(260, 120); shell.open(); System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:LayoutTerm.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); System.out.println("Bounds: " + shell.getBounds()); System.out.println("Client area: " + shell.getClientArea()); shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); RowLayout rowLayout = new RowLayout(); shell.setLayout(rowLayout);/* w w w . j a va2s . c o m*/ Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button2"); Button button3 = new Button(shell, SWT.PUSH); button3.setText("button33333333333333333333333333333333333333"); shell.pack(); shell.open(); System.out.println("button1: " + button1.getBounds()); System.out.println("button2: " + button2.getBounds()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet205.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); shell.setText("Embedding objects in text"); final Image[] images = { new Image(display, 32, 32), new Image(display, 20, 40), new Image(display, 40, 20) }; int[] colors = { SWT.COLOR_BLUE, SWT.COLOR_MAGENTA, SWT.COLOR_GREEN }; for (int i = 0; i < images.length; i++) { GC gc = new GC(images[i]); gc.setBackground(display.getSystemColor(colors[i])); gc.fillRectangle(images[i].getBounds()); gc.dispose();/*w w w . j a v a 2 s . c o m*/ } final Button button = new Button(shell, SWT.PUSH); button.setText("Button"); button.pack(); String text = "Here is some text with a blue image \uFFFC, a magenta image \uFFFC, a green image \uFFFC, and a button: \uFFFC."; final int[] imageOffsets = { 36, 55, 72 }; final TextLayout layout = new TextLayout(display); layout.setText(text); for (int i = 0; i < images.length; i++) { Rectangle bounds = images[i].getBounds(); TextStyle imageStyle = new TextStyle(null, null, null); imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width); layout.setStyle(imageStyle, imageOffsets[i], imageOffsets[i]); } Rectangle bounds = button.getBounds(); TextStyle buttonStyle = new TextStyle(null, null, null); buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width); final int buttonOffset = text.length() - 2; layout.setStyle(buttonStyle, buttonOffset, buttonOffset); shell.addListener(SWT.Paint, event -> { GC gc = event.gc; Point margin = new Point(10, 10); layout.setWidth(shell.getClientArea().width - 2 * margin.x); layout.draw(event.gc, margin.x, margin.y); for (int i = 0; i < images.length; i++) { int offset = imageOffsets[i]; int lineIndex1 = layout.getLineIndex(offset); FontMetrics lineMetrics1 = layout.getLineMetrics(lineIndex1); Point point1 = layout.getLocation(offset, false); GlyphMetrics glyphMetrics1 = layout.getStyle(offset).metrics; gc.drawImage(images[i], point1.x + margin.x, point1.y + margin.y + lineMetrics1.getAscent() - glyphMetrics1.ascent); } int lineIndex2 = layout.getLineIndex(buttonOffset); FontMetrics lineMetrics2 = layout.getLineMetrics(lineIndex2); Point point2 = layout.getLocation(buttonOffset, false); GlyphMetrics glyphMetrics2 = layout.getStyle(buttonOffset).metrics; button.setLocation(point2.x + margin.x, point2.y + margin.y + lineMetrics2.getAscent() - glyphMetrics2.ascent); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } layout.dispose(); for (int i = 0; i < images.length; i++) { images[i].dispose(); } display.dispose(); }
From source file:TextLayoutImageControl.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED); shell.setText("Embedding objects in text"); final Image[] images = { new Image(display, 32, 32), new Image(display, 20, 40), new Image(display, 40, 20) }; int[] colors = { SWT.COLOR_BLUE, SWT.COLOR_MAGENTA, SWT.COLOR_GREEN }; for (int i = 0; i < images.length; i++) { GC gc = new GC(images[i]); gc.setBackground(display.getSystemColor(colors[i])); gc.fillRectangle(images[i].getBounds()); gc.dispose();/*from www . j a v a 2 s . c o m*/ } final Button button = new Button(shell, SWT.PUSH); button.setText("Button"); button.pack(); String text = "Here is some text with a blue image \uFFFC, a magenta image \uFFFC, a green image \uFFFC, and a button: \uFFFC."; final int[] imageOffsets = { 36, 55, 72 }; final TextLayout layout = new TextLayout(display); layout.setText(text); for (int i = 0; i < images.length; i++) { Rectangle bounds = images[i].getBounds(); TextStyle imageStyle = new TextStyle(null, null, null); imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width); layout.setStyle(imageStyle, imageOffsets[i], imageOffsets[i]); } Rectangle bounds = button.getBounds(); TextStyle buttonStyle = new TextStyle(null, null, null); buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width); final int buttonOffset = text.length() - 2; layout.setStyle(buttonStyle, buttonOffset, buttonOffset); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { GC gc = event.gc; Point margin = new Point(10, 10); layout.setWidth(shell.getClientArea().width - 2 * margin.x); layout.draw(event.gc, margin.x, margin.y); for (int i = 0; i < images.length; i++) { int offset = imageOffsets[i]; int lineIndex = layout.getLineIndex(offset); FontMetrics lineMetrics = layout.getLineMetrics(lineIndex); Point point = layout.getLocation(offset, false); GlyphMetrics glyphMetrics = layout.getStyle(offset).metrics; gc.drawImage(images[i], point.x + margin.x, point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent); } int lineIndex = layout.getLineIndex(buttonOffset); FontMetrics lineMetrics = layout.getLineMetrics(lineIndex); Point point = layout.getLocation(buttonOffset, false); GlyphMetrics glyphMetrics = layout.getStyle(buttonOffset).metrics; button.setLocation(point.x + margin.x, point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } layout.dispose(); for (int i = 0; i < images.length; i++) { images[i].dispose(); } display.dispose(); }
From source file:org.eclipse.swt.examples.graphics.GraphicAntialiasTab.java
@Override public void createControlPanel(Composite parent) { Composite comp;/*from w w w .ja va 2 s.c o m*/ // create drop down combo for antialiasing comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$ aliasCombo = new Combo(comp, SWT.DROP_DOWN); aliasCombo.add("OFF"); aliasCombo.add("DEFAULT"); aliasCombo.add("ON"); aliasCombo.select(0); aliasCombo.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); menu = cm.createMenu(parent.getParent(), gb -> { ovalColorGB = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the background to the 5th item in the menu (blue) ovalColorGB = (GraphicsBackground) menu.getItem(4).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(ovalColorGB.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.graphics.LineCapTab.java
@Override public void createControlPanel(Composite parent) { Composite comp;/*from ww w . jav a2 s . c om*/ // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { foreground = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the foreground to the 3rd item in the menu (red) foreground = (GraphicsBackground) menu.getItem(2).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(foreground.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.graphics.LineJoinTab.java
@Override public void createControlPanel(Composite parent) { // create drop down combo for choosing clipping Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineJoin")); //$NON-NLS-1$ joinCb = new Combo(comp, SWT.DROP_DOWN); joinCb.add(GraphicsExample.getResourceString("bevel")); //$NON-NLS-1$ joinCb.add(GraphicsExample.getResourceString("miter")); //$NON-NLS-1$ joinCb.add(GraphicsExample.getResourceString("round")); //$NON-NLS-1$ joinCb.select(1);/*w w w. ja v a2 s . c om*/ joinCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { shapeColor = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the shape color to the 4th item in the menu (green) shapeColor = (GraphicsBackground) menu.getItem(3).getData(); // color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(shapeColor.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.graphics.SpiralTab.java
/** * This method creates a spinner for specifying the number of petals. The call to the * createControlPanel method in the super class create the controls that are * defined in the super class.//from w w w . java 2 s .c o m * * @param parent The parent composite */ @Override public void createControlPanel(Composite parent) { super.createControlPanel(parent); // create spinner number of petals Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Petals")); //$NON-NLS-1$ petalSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); petalSpinner.setSelection(8); petalSpinner.setMinimum(3); petalSpinner.setMaximum(20); petalSpinner.addListener(SWT.Selection, event -> example.redraw()); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { foreground = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the foreground to the 2nd item in the menu foreground = (GraphicsBackground) menu.getItem(1).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(foreground.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }