List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell s = new Shell(d); s.setSize(300, 300);//from w w w. j av a2s .c o m s.setText("A FontDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Font"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell s = new Shell(d); s.setSize(300, 300);/* ww w . j a v a2s.c om*/ s.setText("A ColorDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Color"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:DialogOKCancelFormLayout.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); Label label = new Label(dialog, SWT.NONE); label.setText("Exit the application?"); Button okButton = new Button(dialog, SWT.PUSH); okButton.setText("&OK"); Button cancelButton = new Button(dialog, SWT.PUSH); cancelButton.setText("&Cancel"); FormLayout form = new FormLayout(); form.marginWidth = form.marginHeight = 8; dialog.setLayout(form);//from w w w .j a v a 2 s .co m FormData okData = new FormData(); okData.top = new FormAttachment(label, 8); okButton.setLayoutData(okData); FormData cancelData = new FormData(); cancelData.left = new FormAttachment(okButton, 8); cancelData.top = new FormAttachment(okButton, 0, SWT.TOP); cancelButton.setLayoutData(cancelData); dialog.setDefaultButton(okButton); dialog.pack(); dialog.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet224.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 224"); shell.setLayout(new RowLayout(SWT.VERTICAL)); for (int i = 0; i < 8; i++) { Button button = new Button(shell, SWT.RADIO); button.setText("B" + i); if (i == 0) button.setSelection(true);//from ww w. j a v a 2 s . co m } Button button = new Button(shell, SWT.PUSH); button.setText("Set Selection to B4"); button.addListener(SWT.Selection, event -> { Control[] children = shell.getChildren(); Button newButton = (Button) children[4]; for (int i = 0; i < children.length; i++) { Control child = children[i]; if (child instanceof Button && (child.getStyle() & SWT.RADIO) != 0) { ((Button) child).setSelection(false); } } newButton.setSelection(true); }); 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) { Display d = new Display(); Shell s = new Shell(d); s.setText("A Tabbed Shell Example"); s.setLayout(new FillLayout()); TabFolder tf = new TabFolder(s, SWT.BORDER); TabItem ti1 = new TabItem(tf, SWT.BORDER); ti1.setText("Option Group"); ti1.setControl(new Text(tf, SWT.MULTI)); TabItem ti2 = new TabItem(tf, SWT.BORDER); ti2.setText("Grid"); ti2.setControl(new Text(tf, SWT.MULTI)); TabItem ti3 = new TabItem(tf, SWT.BORDER); ti3.setText("Text"); Composite c1 = new Composite(tf, SWT.BORDER); c1.setLayout(new FillLayout()); Text t = new Text(c1, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); ti3.setControl(c1);//from w ww. ja v a2 s. co m TabItem ti4 = new TabItem(tf, SWT.BORDER); ti4.setText("Settings"); Composite c2 = new Composite(tf, SWT.BORDER); c2.setLayout(new RowLayout()); Text t2 = new Text(c2, SWT.BORDER | SWT.SINGLE | SWT.WRAP | SWT.V_SCROLL); Button b = new Button(c2, SWT.PUSH | SWT.BORDER); b.setText("Save"); ti4.setControl(c2); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:DialogShellPromptValue.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.pack();// w ww. j a va2 s. c o m 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 = new Listener() { public void handleEvent(Event 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.Snippet225.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 225"); Image image = null;//from w ww. j a v a 2s. co 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 = display.getSystemImage(SWT.ICON_INFORMATION); 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, event -> tip.setVisible(true)); Rectangle clientArea = shell.getClientArea(); button.setLocation(clientArea.x, clientArea.y); 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:BusyIndicatorDemo.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("BusyIndicator Test"); shell.setLayout(new FillLayout()); final Button button = new Button(shell, SWT.PUSH); button.setText(RUN); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Change the button's text button.setText(IS_RUNNING);/*from ww w . j a va2 s .co m*/ // Show the busy indicator BusyIndicator.showWhile(button.getDisplay(), new SleepThread(SLEEP_TIME)); // Thread has completed; reset the button's text button.setText(RUN); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet71.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 71"); shell.pack();/*from w w w . ja va 2s. c o m*/ shell.open(); Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); Label label = new Label(dialog, SWT.NONE); label.setText("Exit the application?"); Button okButton = new Button(dialog, SWT.PUSH); okButton.setText("&OK"); Button cancelButton = new Button(dialog, SWT.PUSH); cancelButton.setText("&Cancel"); FormLayout form = new FormLayout(); form.marginWidth = form.marginHeight = 8; dialog.setLayout(form); FormData okData = new FormData(); okData.top = new FormAttachment(label, 8); okButton.setLayoutData(okData); FormData cancelData = new FormData(); cancelData.left = new FormAttachment(okButton, 8); cancelData.top = new FormAttachment(okButton, 0, SWT.TOP); cancelButton.setLayoutData(cancelData); dialog.setDefaultButton(okButton); dialog.pack(); dialog.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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 w w w . j a v a2 s . c o m } }); browser.setText(html); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }