List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:TableItemUpdateText.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 240);/* www .j a v a2 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.setText("Change"); button.pack(); button.setLocation(10, 180); 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:org.eclipse.swt.snippets.Snippet294.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Regions on a Control"); shell.setLayout(new FillLayout()); shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_RED)); Button b2 = new Button(shell, SWT.PUSH); b2.setText("Button with Regions"); // define a region that looks like a circle with two holes in ot Region region = new Region(); region.add(circle(67, 87, 77));/*from w w w. jav a2s . c o m*/ region.subtract(circle(20, 87, 47)); region.subtract(circle(20, 87, 113)); // define the shape of the button using setRegion b2.setRegion(region); b2.setLocation(100, 50); b2.addListener(SWT.Selection, e -> shell.close()); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet330.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 330"); shell.setLayout(new GridLayout(BUTTONS_PER_ROW, true)); final Browser browser; try {//from w w w. jav a2 s . c om browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = BUTTONS_PER_ROW; browser.setLayoutData(data); { Button setHeaders = new Button(shell, SWT.PUSH); setHeaders.setText("Send custom headers"); setHeaders.addListener(SWT.Selection, event -> browser.setUrl("http://www.ericgiguere.com/tools/http-header-viewer.html", null, new String[] { "User-agent: SWT Browser", "Custom-header: this is just a demo" })); } { Button postTextPlain = new Button(shell, SWT.PUSH); postTextPlain.setText("Post data as 'text/plain'"); postTextPlain.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post", "Plain text passed as postData", new String[] { "content-type: text/plain" })); } { Button postTextPlainUtf8 = new Button(shell, SWT.PUSH); postTextPlainUtf8.setText("Post data as 'text/plain' and specify encoding."); postTextPlainUtf8.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post", "Plain text passed as postData", new String[] { "content-type: text/plain; charset=UTF-8" })); } { Button postUrlEncoded = new Button(shell, SWT.PUSH); postUrlEncoded.setText("Post data with url encoding key=value"); postUrlEncoded.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post", "MyKey1=MyValue1&MyKey2=MyValue2", new String[] { "content-type: application/x-www-form-urlencoded" })); } { Button postDataBugzilla = new Button(shell, SWT.PUSH); postDataBugzilla.setText("Send post data to bugzilla. url encoding is used as default"); postDataBugzilla.addListener(SWT.Selection, event -> browser.setUrl( "https://bugs.eclipse.org/bugs/buglist.cgi", "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring", null)); } { Button postDataBugzillaLongQuery = new Button(shell, SWT.PUSH); postDataBugzillaLongQuery.setText("Send post data to bugzilla. Very slow response"); postDataBugzillaLongQuery.addListener(SWT.Selection, event -> browser.setUrl("https://bugs.eclipse.org/bugs/buglist.cgi", "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW", null)); } shell.setSize(1000, 1000); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet106.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 106"); shell.setLayout(new RowLayout(SWT.VERTICAL)); final Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setHeaderVisible(true);/*from w ww . ja va 2 s . co m*/ for (int i = 0; i < 4; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText("Column " + i); } final TableColumn[] columns = table.getColumns(); for (int i = 0; i < 12; i++) { TableItem item = new TableItem(table, SWT.NONE); for (int j = 0; j < columns.length; j++) { item.setText(j, "Item " + i); } } for (int i = 0; i < columns.length; i++) columns[i].pack(); Button button = new Button(shell, SWT.PUSH); final int index = 1; button.setText("Insert Column " + index + "a"); button.addListener(SWT.Selection, e -> { TableColumn column = new TableColumn(table, SWT.NONE, index); column.setText("Column " + index + "a"); TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { items[i].setText(index, "Item " + i + "a"); } column.pack(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet186.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 186"); shell.setLayout(new GridLayout(2, false)); final Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Button go = new Button(shell, SWT.PUSH); go.setText("Go"); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); OleControlSite controlSite;//from w ww .j a v a 2s. co m OleAutomation automation; try { controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); automation = new OleAutomation(controlSite); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTException ex) { System.out.println("Unable to open activeX control"); display.dispose(); return; } final OleAutomation auto = automation; go.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { String url = text.getText(); int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[1]; rgvarg[0] = new Variant(url); int[] rgdispidNamedArgs = new int[1]; rgdispidNamedArgs[0] = rgdispid[1]; auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); } }); // Read PostData whenever we navigate to a site that uses it int BeforeNavigate2 = 0xfa; controlSite.addEventListener(BeforeNavigate2, new OleListener() { @Override public void handleEvent(OleEvent event) { Variant url = event.arguments[1]; Variant postData = event.arguments[4]; if (postData != null) { System.out.println("PostData = " + readSafeArray(postData) + ", URL = " + url.getString()); } } }); // Navigate to this web site which uses post data to fill in the text field // and put the string "hello world" into the text box text.setText("file://" + Snippet186.class.getResource("Snippet186.html").getFile()); int[] rgdispid = automation.getIDsOfNames(new String[] { "Navigate", "URL", "PostData" }); int dispIdMember = rgdispid[0]; Variant[] rgvarg = new Variant[2]; rgvarg[0] = new Variant(text.getText()); rgvarg[1] = writeSafeArray("hello world"); int[] rgdispidNamedArgs = new int[2]; rgdispidNamedArgs[0] = rgdispid[1]; rgdispidNamedArgs[1] = rgdispid[2]; automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:DialogLayoutDemo.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Label label = new Label(shell, SWT.WRAP); label.setText("This is a long text string that will wrap when the dialog is resized."); List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); list.setItems(new String[] { "Item 1", "Item 2" }); Button button1 = new Button(shell, SWT.PUSH); button1.setText("OK"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Cancel"); final int insetX = 4, insetY = 4; FormLayout formLayout = new FormLayout(); formLayout.marginWidth = insetX;//from w ww . ja v a 2 s . c o m formLayout.marginHeight = insetY; shell.setLayout(formLayout); Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT); final FormData labelData = new FormData(size.x, SWT.DEFAULT); labelData.left = new FormAttachment(0, 0); labelData.right = new FormAttachment(100, 0); label.setLayoutData(labelData); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = shell.getClientArea(); labelData.width = rect.width - insetX * 2; shell.layout(); } }); FormData button2Data = new FormData(); button2Data.right = new FormAttachment(100, -insetX); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); FormData button1Data = new FormData(); button1Data.right = new FormAttachment(button2, -insetX); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); FormData listData = new FormData(); listData.left = new FormAttachment(0, 0); listData.right = new FormAttachment(100, 0); listData.top = new FormAttachment(label, insetY); listData.bottom = new FormAttachment(button2, -insetY); list.setLayoutData(listData); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeEditorButton.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Text Tree Editor"); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.SINGLE); for (int i = 0; i < 3; i++) { TreeItem iItem = new TreeItem(tree, SWT.NONE); iItem.setText("Item " + (i + 1)); for (int j = 0; j < 3; j++) { TreeItem jItem = new TreeItem(iItem, SWT.NONE); jItem.setText("Sub Item " + (j + 1)); for (int k = 0; k < 3; k++) { new TreeItem(jItem, SWT.NONE).setText("Sub Sub Item " + (k + 1)); }/* ww w . j a v a 2 s .c o m*/ jItem.setExpanded(true); } iItem.setExpanded(true); } final TreeEditor editor = new TreeEditor(tree); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; tree.addMouseListener(new MouseAdapter() { public void mouseDown(MouseEvent event) { final TreeItem item = tree.getSelection()[0]; final Button bn = new Button(tree, SWT.NONE); bn.setText("click"); bn.setFocus(); bn.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { int style = SWT.ICON_QUESTION | SWT.YES | SWT.NO; MessageBox messageBox = new MessageBox(shell, style); messageBox.setMessage("Message"); int rc = messageBox.open(); item.setText(rc + ""); bn.dispose(); } public void widgetDefaultSelected(SelectionEvent arg0) { } }); editor.setEditor(bn, item); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:CaptureWidgetImageGC.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Widget"); final Table table = new Table(shell, SWT.MULTI); table.setLinesVisible(true);/* w ww . j av a2 s.c o m*/ 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.pack(); button.setLocation(10, 140); 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.addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { image.dispose(); } }); Canvas canvas = new Canvas(popup, SWT.NONE); canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); popup.pack(); popup.open(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet287.java
public static void main(String[] args) { final String SEARCH_STRING = "4b"; Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 287"); shell.setBounds(10, 10, 300, 300);//from ww w.ja v a 2 s . co m shell.setLayout(new GridLayout()); /* create the Tree */ tree = new Tree(shell, SWT.FULL_SELECTION); tree.setLinesVisible(true); tree.setLayoutData(new GridData(GridData.FILL_BOTH)); for (int i = 0; i < 3; i++) { new TreeColumn(tree, SWT.NONE).setWidth(90); } int index = 0; for (int i = 0; i < 3; i++) { TreeItem item = createItem(null, index++); for (int j = 0; j < i; j++) { item = createItem(item, index++); } } Button button = new Button(shell, SWT.PUSH); button.setText("Find '" + SEARCH_STRING + "'"); button.addListener(SWT.Selection, event -> { int itemCount = tree.getItemCount(); for (int i = 0; i < itemCount; i++) { TreeItem item = tree.getItem(i); boolean success = find(item, SEARCH_STRING); if (success) { System.out.println("Found it"); return; } } System.out.println("Did not find it"); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet201.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 201"); shell.setLayout(new RowLayout(SWT.VERTICAL)); final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER); table.addListener(SWT.SetData, event -> { TableItem item = (TableItem) event.item; int index = table.indexOf(item); int start = index / PAGE_SIZE * PAGE_SIZE; int end = Math.min(start + PAGE_SIZE, table.getItemCount()); for (int i = start; i < end; i++) { item = table.getItem(i);/*from ww w .ja v a 2 s. c o m*/ item.setText("Item " + i); } }); table.setLayoutData(new RowData(200, 200)); Button button = new Button(shell, SWT.PUSH); button.setText("Add Items"); final Label label = new Label(shell, SWT.NONE); button.addListener(SWT.Selection, event -> { long t1 = System.currentTimeMillis(); table.setItemCount(COUNT); long t2 = System.currentTimeMillis(); label.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]"); shell.layout(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }