List of usage examples for org.eclipse.swt.widgets Button setBounds
public void setBounds(int x, int y, int width, int height)
From source file:ClipBoardCopyPaster.java
public static void main(String[] args) { Display display = new Display(); final Clipboard cb = new Clipboard(display); final Shell shell = new Shell(display); final Text text = new Text(shell, SWT.BORDER | SWT.SINGLE); text.setBounds(5, 5, 100, 20);// w w w . jav a 2 s .c o m Button copy = new Button(shell, SWT.PUSH); copy.setBounds(5, 50, 100, 20); copy.setText("Copy"); copy.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String textData = text.getSelectionText(); if (textData.length() > 0) { TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer }); } } }); Button paste = new Button(shell, SWT.PUSH); paste.setBounds(5, 90, 100, 20); paste.setText("Paste"); paste.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { TextTransfer transfer = TextTransfer.getInstance(); String data = (String) cb.getContents(transfer); if (data != null) { text.insert(data); } } }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cb.dispose(); display.dispose(); }
From source file:Snippet103.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 240);//from w w w .j av a 2 s. c o m Table table = new Table(shell, SWT.NONE); table.setBounds(10, 10, 160, 160); final TableItem[] items = new TableItem[4]; for (int i = 0; i < 4; i++) { new TableColumn(table, SWT.NONE).setWidth(40); } for (int i = 0; i < 4; i++) { items[i] = new TableItem(table, SWT.NONE); populateItem(items[i]); } Button button = new Button(shell, SWT.PUSH); button.setBounds(10, 180, 50, 30); button.setText("Change"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { for (int i = 0; i < 4; i++) { populateItem(items[i]); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Shell shell = new Shell(new Display()); final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); dialog.setText("Delete File"); dialog.setSize(250, 150);/*from w w w .j a v a 2s .c om*/ final Button buttonOK = new Button(dialog, SWT.PUSH); buttonOK.setText("OK"); buttonOK.setBounds(20, 55, 80, 25); Button buttonCancel = new Button(dialog, SWT.PUSH); buttonCancel.setText("Cancel"); buttonCancel.setBounds(120, 55, 80, 25); final Label label = new Label(dialog, SWT.NONE); label.setText("Delete the file?"); label.setBounds(20, 15, 100, 20); Listener listener = new Listener() { public void handleEvent(Event event) { if (event.widget == buttonOK) { System.out.println("OK"); } else { System.out.println("Cancel"); } dialog.close(); } }; buttonOK.addListener(SWT.Selection, listener); buttonCancel.addListener(SWT.Selection, listener); dialog.open(); }
From source file:Snippet21.java
public static void main(String[] args) { Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); Button b = new Button(shell, SWT.PUSH); b.setBounds(10, 10, 100, 32); b.setText("Button"); shell.setDefaultButton(b);//from ww w . j ava 2 s. c o m final Canvas c = new Canvas(shell, SWT.BORDER); c.setBounds(10, 50, 100, 32); c.addListener(SWT.Traverse, new Listener() { public void handleEvent(Event e) { switch (e.detail) { /* Do tab group traversal */ case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: case SWT.TRAVERSE_PAGE_NEXT: case SWT.TRAVERSE_PAGE_PREVIOUS: e.doit = true; break; } } }); c.addListener(SWT.FocusIn, new Listener() { public void handleEvent(Event e) { c.setBackground(red); } }); c.addListener(SWT.FocusOut, new Listener() { public void handleEvent(Event e) { c.setBackground(blue); } }); c.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event e) { System.out.println("KEY"); for (int i = 0; i < 64; i++) { Color c1 = red, c2 = blue; if (c.isFocusControl()) { c1 = blue; c2 = red; } c.setBackground(c1); c.update(); c.setBackground(c2); } } }); Text t = new Text(shell, SWT.SINGLE | SWT.BORDER); t.setBounds(10, 85, 100, 32); Text r = new Text(shell, SWT.MULTI | SWT.BORDER); r.setBounds(10, 120, 100, 32); c.setFocus(); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet249.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 249"); Rectangle clientArea = shell.getClientArea(); shell.setBounds(clientArea.x + 10, clientArea.y + 10, 300, 200); // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(clientArea.x + 100, clientArea.y + 10, 190, 90); final StackLayout layout = new StackLayout(); contentPanel.setLayout(layout);//from ww w . j a v a 2 s . com // create the first page's content final Composite page0 = new Composite(contentPanel, SWT.NONE); page0.setLayout(new RowLayout()); Label label = new Label(page0, SWT.NONE); label.setText("Label on page 1"); label.pack(); // create the second page's content final Composite page1 = new Composite(contentPanel, SWT.NONE); page1.setLayout(new RowLayout()); Button button = new Button(page1, SWT.NONE); button.setText("Button on page 2"); button.pack(); // create the button that will switch between the pages Button pageButton = new Button(shell, SWT.PUSH); pageButton.setText("Push"); pageButton.setBounds(clientArea.x + 10, clientArea.y + 10, 80, 25); pageButton.addListener(SWT.Selection, event -> { pageNum = ++pageNum % 2; layout.topControl = pageNum == 0 ? page0 : page1; contentPanel.layout(); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet44.java
public static void main(String[] args) { Display display = new Display(); final Cursor cursor = display.getSystemCursor(SWT.CURSOR_HAND); Shell shell = new Shell(display); shell.setText("Snippet 44"); shell.open();//from ww w .ja v a2 s .co m final Button b = new Button(shell, 0); b.setText("Push to set cursor to hand"); Rectangle clientArea = shell.getClientArea(); b.setBounds(clientArea.x + 10, clientArea.y + 10, 200, 200); b.addListener(SWT.Selection, e -> b.setCursor(cursor)); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:StackLayoutSwitchComposites.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 300, 200);//from w w w .j a v a 2s .co m // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(100, 10, 190, 90); final StackLayout layout = new StackLayout(); contentPanel.setLayout(layout); // create the first page's content final Composite page0 = new Composite(contentPanel, SWT.NONE); page0.setLayout(new RowLayout()); Label label = new Label(page0, SWT.NONE); label.setText("Label on page 1"); label.pack(); // create the second page's content final Composite page1 = new Composite(contentPanel, SWT.NONE); page1.setLayout(new RowLayout()); Button button = new Button(page1, SWT.NONE); button.setText("Button on page 2"); button.pack(); // create the button that will switch between the pages Button pageButton = new Button(shell, SWT.PUSH); pageButton.setText("Push"); pageButton.setBounds(10, 10, 80, 25); pageButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { pageNum = ++pageNum % 2; layout.topControl = pageNum == 0 ? page0 : page1; contentPanel.layout(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet95.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Widget"); shell.setBounds(10, 10, 200, 200);/* w w w .j a v a 2s. co m*/ final Table table = new Table(shell, SWT.MULTI); table.setLinesVisible(true); table.setBounds(10, 10, 100, 100); for (int i = 0; i < 9; i++) { new TableItem(table, SWT.NONE).setText("item" + i); } Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.setBounds(10, 140, 50, 20); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { Point tableSize = table.getSize(); GC gc = new GC(table); final Image image = new Image(display, tableSize.x, tableSize.y); gc.copyArea(image, 0, 0); gc.dispose(); Shell popup = new Shell(shell); popup.setText("Image"); popup.setBounds(50, 50, 200, 200); popup.addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { image.dispose(); } }); Canvas canvas = new Canvas(popup, SWT.NONE); canvas.setBounds(10, 10, 150, 150); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); popup.open(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet21.java
public static void main(String[] args) { Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setText("Snippet 21"); Button b = new Button(shell, SWT.PUSH); Rectangle clientArea = shell.getClientArea(); b.setBounds(clientArea.x + 10, clientArea.y + 10, 100, 32); b.setText("Button"); shell.setDefaultButton(b);//from w w w .j a v a 2s.com final Canvas c = new Canvas(shell, SWT.BORDER); c.setBounds(10, 50, 100, 32); c.addListener(SWT.Traverse, e -> { switch (e.detail) { /* Do tab group traversal */ case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: case SWT.TRAVERSE_PAGE_NEXT: case SWT.TRAVERSE_PAGE_PREVIOUS: e.doit = true; break; } }); c.addListener(SWT.FocusIn, e -> c.setBackground(red)); c.addListener(SWT.FocusOut, e -> c.setBackground(blue)); c.addListener(SWT.KeyDown, e -> System.out.println("KEY")); Text t = new Text(shell, SWT.SINGLE | SWT.BORDER); t.setBounds(10, 85, 100, 32); Text r = new Text(shell, SWT.MULTI | SWT.BORDER); r.setBounds(10, 120, 100, 32); c.setFocus(); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet324.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 324"); Listener listener = e -> {//w ww . j a v a 2 s . c om String string = "Unknown"; switch (e.type) { case SWT.MouseDoubleClick: string = "DOUBLE-CLICK"; break; case SWT.MouseDown: string = "DOWN"; break; case SWT.MouseMove: string = "MOVE"; break; case SWT.MouseUp: string = "UP"; break; case SWT.MouseEnter: string = "ENTER"; break; case SWT.MouseExit: string = "EXIT"; break; case SWT.MouseVerticalWheel: string = "WHEEL VERTICAL"; break; case SWT.MouseHorizontalWheel: string = "WHEEL HORIZONTAL"; break; } string += " - button=" + e.button + ", "; string += "stateMask=0x" + Integer.toHexString(e.stateMask) + stateMask(e.stateMask); string += "location=(" + e.x + ", " + e.y + "), "; if (e.type == SWT.MouseVerticalWheel) { string += "detail="; string += e.detail == SWT.SCROLL_PAGE ? "SCROLL_PAGE, " : "SCROLL_LINE, "; } string += "count=" + e.count + ", widget=" + e.widget; System.out.println(string); }; shell.addListener(SWT.MouseDoubleClick, listener); shell.addListener(SWT.MouseDown, listener); shell.addListener(SWT.MouseMove, listener); shell.addListener(SWT.MouseUp, listener); shell.addListener(SWT.MouseEnter, listener); shell.addListener(SWT.MouseExit, listener); shell.addListener(SWT.MouseWheel, listener); shell.addListener(SWT.MouseHorizontalWheel, listener); Button button = new Button(shell, SWT.PUSH); button.setBounds(10, 10, 100, 100); button.addListener(SWT.MouseDoubleClick, listener); button.addListener(SWT.MouseDown, listener); button.addListener(SWT.MouseMove, listener); button.addListener(SWT.MouseUp, listener); button.addListener(SWT.MouseEnter, listener); button.addListener(SWT.MouseExit, listener); button.addListener(SWT.MouseWheel, listener); button.addListener(SWT.MouseHorizontalWheel, listener); shell.setSize(240, 240); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }