List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:Snippet186.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); 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 w w. j a v a 2s . c o m*/ OleAutomation automation; try { controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); automation = new OleAutomation(controlSite); controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); } catch (SWTException ex) { return; } final OleAutomation auto = automation; go.addListener(SWT.Selection, new Listener() { 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() { 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:org.eclipse.swt.snippets.Snippet247.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 247"); shell.setLayout(new RowLayout()); Text text = new Text(shell, SWT.MULTI | SWT.BORDER); String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command"; text.setText("Hit " + modifier + "+Return\nto see\nthe default button\nrun"); text.addTraverseListener(e -> {/*from w ww . j a va2s . com*/ switch (e.detail) { case SWT.TRAVERSE_RETURN: if ((e.stateMask & SWT.MOD1) != 0) e.doit = true; } }); Button button = new Button(shell, SWT.PUSH); button.pack(); button.setText("OK"); button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("OK selected"))); shell.setDefaultButton(button); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet214.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 214"); shell.setBackgroundMode(SWT.INHERIT_DEFAULT); FillLayout layout1 = new FillLayout(SWT.VERTICAL); layout1.marginWidth = layout1.marginHeight = 10; shell.setLayout(layout1);//from w w w . j av a2 s. co m Group group = new Group(shell, SWT.NONE); group.setText("Group "); RowLayout layout2 = new RowLayout(SWT.VERTICAL); layout2.marginWidth = layout2.marginHeight = layout2.spacing = 10; group.setLayout(layout2); for (int i = 0; i < 8; i++) { Button button = new Button(group, SWT.RADIO); button.setText("Button " + i); } shell.addListener(SWT.Resize, event -> { Rectangle rect = shell.getClientArea(); Image newImage = new Image(display, Math.max(1, rect.width), 1); GC gc = new GC(newImage); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false); gc.dispose(); shell.setBackgroundImage(newImage); if (oldImage != null) oldImage.dispose(); oldImage = newImage; }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (oldImage != null) oldImage.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet223.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = display.getSystemImage(SWT.ICON_QUESTION); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;/*from w w w . j a v a2s .com*/ composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); // Second item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 1); item1.setText("What is your favorite icon"); item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item1.setControl(composite); item1.setImage(image); // Third item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); label = new Label(composite, SWT.NONE); label.setText("Scale"); new Scale(composite, SWT.NONE); label = new Label(composite, SWT.NONE); label.setText("Spinner"); new Spinner(composite, SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Slider"); new Slider(composite, SWT.NONE); ExpandItem item2 = new ExpandItem(bar, SWT.NONE, 2); item2.setText("What is your favorite range widget"); item2.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item2.setControl(composite); item2.setImage(image); item1.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet347.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 347"); shell.setLayout(new GridLayout(1, false)); Menu appMenuBar = display.getMenuBar(); if (appMenuBar == null) { appMenuBar = new Menu(shell, SWT.BAR); shell.setMenuBar(appMenuBar);//from w ww .j a v a 2s . c o m } MenuItem file = new MenuItem(appMenuBar, SWT.CASCADE); file.setText("File"); Menu dropdown = new Menu(appMenuBar); file.setMenu(dropdown); MenuItem exit = new MenuItem(dropdown, SWT.PUSH); exit.setText("Exit"); exit.addSelectionListener(widgetSelectedAdapter(e -> display.dispose())); Button b = new Button(shell, SWT.PUSH); b.setText("Test"); shell.pack(); shell.open(); 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 ww . j av a2 s. com*/ } 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:org.eclipse.swt.snippets.Snippet292.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 292"); final Group group = new Group(shell, SWT.NONE); group.setText("Group"); group.setLayout(new GridLayout()); final Tree tree = new Tree(group, SWT.BORDER); for (int i = 0; i < 5; i++) { TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText("TreeItem " + i); for (int j = 0; j < 3; j++) { TreeItem subItem = new TreeItem(treeItem, SWT.NONE); subItem.setText("SubItem " + i + "-" + j); }//from ww w .j a v a 2s. c om if (i % 3 == 0) treeItem.setExpanded(true); } new Button(group, SWT.PUSH).setText("Button"); final Label label = new Label(shell, SWT.NONE); label.addListener(SWT.Dispose, e -> { Image image = label.getImage(); if (image != null) image.dispose(); }); Button button = new Button(shell, SWT.PUSH); button.setText("Snapshot"); button.addListener(SWT.Selection, e -> { Image image = label.getImage(); if (image != null) image.dispose(); image = new Image(display, group.getBounds()); GC gc = new GC(image); boolean success = group.print(gc); gc.dispose(); label.setImage(image); if (!success) { MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.PRIMARY_MODAL); messageBox.setMessage("Sorry, taking a snapshot is not supported on your platform"); messageBox.open(); } }); GridLayout layout = new GridLayout(2, true); shell.setLayout(layout); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet147.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 147"); shell.setLayout(new GridLayout()); Combo combo = new Combo(shell, SWT.NONE); combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); combo.setText("Here is some text"); combo.addSelectionListener(widgetDefaultSelectedAdapter( e -> System.out.println("Combo default selected (overrides default button)"))); combo.addTraverseListener(e -> {/* w w w . java 2s. c om*/ if (e.detail == SWT.TRAVERSE_RETURN) { e.doit = false; e.detail = SWT.TRAVERSE_NONE; } }); Button button = new Button(shell, SWT.PUSH); button.setText("Ok"); button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Button selected"))); shell.setDefaultButton(button); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet116.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 116"); shell.setLayout(new GridLayout()); Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setText("Here is some text"); text.addSelectionListener(widgetDefaultSelectedAdapter( e -> System.out.println("Text default selected (overrides default button)"))); text.addTraverseListener(e -> {/* w w w.j a va 2 s .co m*/ if (e.detail == SWT.TRAVERSE_RETURN) { e.doit = false; e.detail = SWT.TRAVERSE_NONE; } }); Button button = new Button(shell, SWT.PUSH); button.setText("Ok"); button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Button selected"))); shell.setDefaultButton(button); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet126.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setLinesVisible(true);/* w ww . j av a 2 s . c om*/ 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); editor.grabHorizontal = true; editor.setEditor(combo, items[i], 0); editor = new TableEditor(table); Text text = new Text(table, SWT.NONE); 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(); }