List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:ModifyDOM.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) { /*/*ww w. j a v a 2s . c o m*/ * 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:GridLayoutGrabExcessVertical.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;//from w w w . ja v a2 s . c o m gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); // Default alignment List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = GridData.FILL; list.setLayoutData(gridData); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); GridData gridData2 = new GridData(); gridData2.grabExcessVerticalSpace = true; gridData2.verticalAlignment = GridData.FILL; button2.setLayoutData(gridData2); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display d = new Display(); Shell s = new Shell(d); GridLayout gl = new GridLayout(); gl.numColumns = 4;/*from w ww . jav a 2 s . c o m*/ s.setLayout(gl); s.setSize(250, 275); s.setText("A Shell Composite Example"); s.setLayout(gl); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 4; gd = new GridData(); Composite c1 = new Composite(s, SWT.NO_FOCUS); gd = new GridData(GridData.FILL_HORIZONTAL); c1.setLayoutData(gd); Composite c2 = new Composite(s, SWT.NO_FOCUS); gd = new GridData(GridData.FILL_HORIZONTAL); c2.setLayoutData(gd); Composite c = new Composite(s, SWT.NO_FOCUS); c.setLayout(new RowLayout()); Button b1 = new Button(c, SWT.PUSH | SWT.BORDER); b1.setText("OK"); Button b2 = new Button(c, SWT.PUSH | SWT.BORDER); b2.setText("Cancel"); gd = new GridData(GridData.FILL_HORIZONTAL); c.setLayoutData(gd); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:AsyncExecDisplay.java
public static void main(String[] args) { Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Button buttonAsyncExec = new Button(shell, SWT.PUSH); buttonAsyncExec.setText("start"); buttonAsyncExec.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { }/* www . j a v a2s .c om*/ public void widgetSelected(SelectionEvent e) { buttonAsyncExec.setText("Calculation in progress ..."); getTask2(buttonAsyncExec).start(); } }); shell.open(); while (!shell.isDisposed()) { // Event loop. if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ColorDialogButtonActionSetLabelBackground.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Color Chooser"); shell.setLayout(new GridLayout(2, false)); final Label colorLabel = new Label(shell, SWT.NONE); colorLabel.setText("Color"); Button button = new Button(shell, SWT.PUSH); button.setText("Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color color = new Color(shell.getDisplay(), new RGB(0, 255, 0)); ColorDialog dlg = new ColorDialog(shell); dlg.setRGB(colorLabel.getBackground().getRGB()); dlg.setText("Choose a Color"); RGB rgb = dlg.open();// w ww. java 2s . c o m if (rgb != null) { color.dispose(); color = new Color(shell.getDisplay(), rgb); colorLabel.setBackground(color); color.dispose(); } } }); shell.pack(); 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);/*w ww . j a v a 2 s . com*/ final String RUN = "Press to Run"; final String IS_RUNNING = "Running..."; shell.setLayout(new FillLayout()); final Button button = new Button(shell, SWT.PUSH); button.setText(RUN); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { button.setText(IS_RUNNING); BusyIndicator.showWhile(button.getDisplay(), new SleepThread(1000)); button.setText(RUN); } }); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:ControlListenerAdd.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final Composite composite = new Composite(shell, SWT.BORDER); composite.setLayout(new RowLayout()); composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); composite.addControlListener(new ControlListener() { public void controlMoved(ControlEvent e) { }/*from w w w. j ava2 s . com*/ public void controlResized(ControlEvent e) { System.out.println("Composite resize."); } }); Button buttonAdd = new Button(shell, SWT.PUSH); buttonAdd.setText("Add new button"); buttonAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button = new Button(composite, SWT.PUSH); button.setText("Button #" + (count++)); composite.layout(true); composite.pack(); } }); shell.setSize(450, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet206.java
public static void main(String[] args) { Display display = new Display(); Image image = display.getSystemImage(SWT.ICON_QUESTION); Shell shell = new Shell(display); shell.setText("Snippet 206"); shell.setLayout(new GridLayout()); Button button = new Button(shell, SWT.PUSH); button.setImage(image);//from w w w . j a v a 2 s.c om button.setText("Button"); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet63.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 63"); shell.pack();//from w w w . j a v a 2s . c om shell.open(); final boolean[] result = new boolean[1]; final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setLayout(new RowLayout()); final Button ok = new Button(dialog, SWT.PUSH); ok.setText("OK"); Button cancel = new Button(dialog, SWT.PUSH); cancel.setText("Cancel"); Listener listener = event -> { result[0] = event.widget == ok; dialog.close(); }; ok.addListener(SWT.Selection, listener); cancel.addListener(SWT.Selection, listener); dialog.pack(); dialog.open(); System.out.println("Prompt ..."); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } System.out.println("Result: " + result[0]); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet68.java
public static void main(String[] args) { final 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 68"); shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Stop Timer"); final Label label = new Label(shell, SWT.BORDER); label.setBackground(red);//ww w. j a v a 2 s .c om final int time = 500; final Runnable timer = new Runnable() { @Override public void run() { if (label.isDisposed()) return; Color color = label.getBackground().equals(red) ? blue : red; label.setBackground(color); display.timerExec(time, this); } }; display.timerExec(time, timer); button.addListener(SWT.Selection, event -> display.timerExec(-1, timer)); button.pack(); label.setLayoutData(new RowData(button.getSize())); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }