List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:JavascriptExec.java
public static void main(String[] args) { final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>"; Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Browser browser = new Browser(shell, SWT.BORDER); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout(SWT.VERTICAL)); final Text text = new Text(comp, SWT.MULTI); text.setText("var newNode = document.createElement('P'); \r\n" + "var text = document.createTextNode('At least when I am around');\r\n" + "newNode.appendChild(text);\r\n" + "document.getElementById('myid').appendChild(newNode);\r\n" + "\r\n" + "document.bgColor='yellow';"); final Button button = new Button(comp, SWT.PUSH); button.setText("Execute Script"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { boolean result = browser.execute(text.getText()); if (!result) { /* Script may fail or may not be supported on certain platforms. */ System.out.println("Script was not executed."); }/*from ww w . j a va 2s .c om*/ } }); browser.setText(html); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ToolTipBalloon.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Image image = null;// w w w . j ava2 s . c o m final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION); tip.setMessage( "Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind."); Tray tray = display.getSystemTray(); if (tray != null) { TrayItem item = new TrayItem(tray, SWT.NONE); image = new Image(display, "yourFile.gif"); item.setImage(image); tip.setText("Notification from a tray item"); item.setToolTip(tip); } else { tip.setText("Notification from anywhere"); tip.setLocation(400, 400); } Button button = new Button(shell, SWT.PUSH); button.setText("Press for balloon tip"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { tip.setVisible(true); } }); button.pack(); shell.setBounds(50, 50, 300, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); 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 www . j av a 2 s . c o m*/ // 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:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell shell = new Shell(d); shell.setSize(250, 200);/*from w w w . j a v a 2 s. c om*/ shell.setLayout(new FillLayout()); // Number of rows and columns final int NUM = 5; // Create the table final Table table = new Table(shell, SWT.SINGLE | SWT.FULL_SELECTION | SWT.HIDE_SELECTION); table.setHeaderVisible(true); table.setLinesVisible(true); for (int i = 0; i < NUM; i++) { TableColumn column = new TableColumn(table, SWT.CENTER); column.setText("Column " + (i + 1)); column.pack(); } TableEditor[] colorEditors = new TableEditor[NUM]; Button[] colorButtons = new Button[NUM]; for (int i = 0; i < NUM; i++) { // Create the row final TableItem item = new TableItem(table, SWT.NONE); // Create the editor and button colorEditors[i] = new TableEditor(table); colorButtons[i] = new Button(table, SWT.PUSH); // Set attributes of the button colorButtons[i].setText("Color..."); colorButtons[i].computeSize(SWT.DEFAULT, table.getItemHeight()); // Set attributes of the editor colorEditors[i].grabHorizontal = true; colorEditors[i].minimumHeight = colorButtons[i].getSize().y; colorEditors[i].minimumWidth = colorButtons[i].getSize().x; colorEditors[i].setEditor(colorButtons[i], item, 0); colorButtons[i].addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { System.out.println("pressed"); } }); } shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet161.java
public static void main(String[] args) { final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>"; Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 161"); shell.setLayout(new FillLayout()); final Browser browser; try {/*from ww w . ja v a 2s . c o m*/ browser = new Browser(shell, SWT.BORDER); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout(SWT.VERTICAL)); final Text text = new Text(comp, SWT.MULTI); text.setText("var newNode = document.createElement('P'); \r\n" + "var text = document.createTextNode('At least when I am around');\r\n" + "newNode.appendChild(text);\r\n" + "document.getElementById('myid').appendChild(newNode);\r\n" + "\r\n" + "document.bgColor='yellow';"); final Button button = new Button(comp, SWT.PUSH); button.setText("Execute Script"); button.addListener(SWT.Selection, event -> { boolean result = browser.execute(text.getText()); if (!result) { /* Script may fail or may not be supported on certain platforms. */ System.out.println("Script was not executed."); } }); browser.setText(html); shell.open(); 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);/* w ww . j a va 2 s .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:org.eclipse.swt.snippets.Snippet126.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 126"); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setLinesVisible(true);/*from www.ja v a 2 s .c o m*/ for (int i = 0; i < 3; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(100); } for (int i = 0; i < 12; i++) { new TableItem(table, SWT.NONE); } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { TableEditor editor = new TableEditor(table); CCombo combo = new CCombo(table, SWT.NONE); combo.setText("CCombo"); combo.add("item 1"); combo.add("item 2"); editor.grabHorizontal = true; editor.setEditor(combo, items[i], 0); editor = new TableEditor(table); Text text = new Text(table, SWT.NONE); text.setText("Text"); editor.grabHorizontal = true; editor.setEditor(text, items[i], 1); editor = new TableEditor(table); Button button = new Button(table, SWT.CHECK); button.pack(); editor.minimumWidth = button.getSize().x; editor.horizontalAlignment = SWT.LEFT; editor.setEditor(button, items[i], 2); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } 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 w ww. ja 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:Snippet181.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout(SWT.HORIZONTAL)); final Table table = new Table(shell, SWT.BORDER | SWT.CHECK); table.setLayoutData(new RowData(-1, 300)); table.setHeaderVisible(true);/*w ww . j a va 2 s . c o m*/ TableColumn column = new TableColumn(table, SWT.LEFT); column.setText("Column 0"); column = new TableColumn(table, SWT.CENTER); column.setText("Column 1"); column = new TableColumn(table, SWT.CENTER); column.setText("Column 2"); column = new TableColumn(table, SWT.CENTER); column.setText("Column 3"); column = new TableColumn(table, SWT.CENTER); column.setText("Column 4"); for (int i = 0; i < 100; i++) { TableItem item = new TableItem(table, SWT.NONE); String[] text = new String[] { i + " 0", i + " 1", i + " 2", i + " 3", i + " 4" }; item.setText(text); } Listener listener = new Listener() { public void handleEvent(Event e) { System.out.println("Move " + e.widget); } }; TableColumn[] columns = table.getColumns(); for (int i = 0; i < columns.length; i++) { columns[i].pack(); columns[i].setMoveable(true); columns[i].addListener(SWT.Move, listener); } Button b = new Button(shell, SWT.PUSH); b.setText("invert column order"); b.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int[] order = table.getColumnOrder(); for (int i = 0; i < order.length / 2; i++) { int temp = order[i]; order[i] = order[order.length - i - 1]; order[order.length - i - 1] = temp; } table.setColumnOrder(order); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet115.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 115"); shell.setLayout(new RowLayout(SWT.VERTICAL)); Composite c1 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP); c1.setLayout(new RowLayout()); Composite c2 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP); c2.setLayout(new RowLayout()); final Composite[] composites = new Composite[] { c1, c2 }; Listener radioGroup = event -> {/*from w ww . j ava 2 s. c om*/ for (int i = 0; i < composites.length; i++) { Composite composite = composites[i]; Control[] children = composite.getChildren(); for (int j = 0; j < children.length; j++) { Control child = children[j]; if (child instanceof Button) { Button button1 = (Button) child; if ((button1.getStyle() & SWT.RADIO) != 0) button1.setSelection(false); } } } Button button2 = (Button) event.widget; button2.setSelection(true); }; for (int i = 0; i < 4; i++) { Button button = new Button(c1, SWT.RADIO); button.setText("Button " + i); button.addListener(SWT.Selection, radioGroup); } for (int i = 0; i < 4; i++) { Button button = new Button(c2, SWT.RADIO); button.setText("Button " + (i + 4)); button.addListener(SWT.Selection, radioGroup); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }