List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:ToolTipBalloon.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Image image = null;/*from w w w . j ava2s. 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 = 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:FocusTraversal.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setLayout(new RowLayout()); composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); Button button1 = new Button(composite1, SWT.PUSH); button1.setText("Button1"); Button button3 = new Button(composite1, SWT.PUSH); button3.setText("Button3"); Button radioButton1 = new Button(composite1, SWT.RADIO); radioButton1.setText("radio-1"); Button radioButton2 = new Button(composite1, SWT.RADIO); radioButton2.setText("radio-2"); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new RowLayout()); composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); Button button2 = new Button(composite2, SWT.PUSH); button2.setText("Button2"); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0);//w w w .jav a2 s . com composite1.setTabList(new Control[] { button1, button3 }); composite2.setTabList(new Control[] { button2, combo }); shell.setTabList(new Control[] { composite2, composite1 }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:org.eclipse.swt.snippets.Snippet182.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 182"); shell.setLayout(new RowLayout()); Link link = new Link(shell, SWT.BORDER); link.setText("This a very simple <a>link</a> widget."); Button setButton = new Button(shell, SWT.PUSH); setButton.setText("Choose link color"); setButton.addSelectionListener(widgetSelectedAdapter(e -> { System.out.println("default link color " + link.getLinkForeground()); ColorDialog colorDialog = new ColorDialog(shell); RGB color = colorDialog.open();/*w w w. ja v a 2 s . com*/ link.setLinkForeground(new Color(display, color)); System.out.println("user selected link color " + link.getLinkForeground()); })); Button resetButton = new Button(shell, SWT.PUSH); resetButton.setText("Reset link color"); resetButton.addSelectionListener(widgetSelectedAdapter(e -> { System.out.println("link color reset to system default"); link.setLinkForeground(null); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ButtonDefaultShell.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final String[] ratings = new String[] { "A!", "B", "C" }; final Button[] radios = new Button[ratings.length]; for (int i = 0; i < ratings.length; i++) { radios[i] = new Button(shell, SWT.RADIO); radios[i].setText(ratings[i]);/* www . ja v a 2 s . c om*/ } Button cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Canel"); Button rateButton = new Button(shell, SWT.PUSH); rateButton.setText("OK"); rateButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { for (int i = 0; i < radios.length; i++) { if (radios[i].getSelection()) { System.out.println(ratings[i]); } } } public void widgetDefaultSelected(SelectionEvent e) { for (int i = 0; i < radios.length; i++) { if (radios[i].getSelection()) { System.out.println(ratings[i]); } } } }); shell.setDefaultButton(rateButton); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:org.eclipse.swt.snippets.Snippet103.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 103"); shell.setBounds(10, 10, 200, 240);/*from w ww . j av a 2 s .c o m*/ Table table = new Table(shell, SWT.NONE); Rectangle clientArea = shell.getClientArea(); table.setBounds(clientArea.x + 10, clientArea.y + 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, 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));// w ww . j a va 2 s . com 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.Snippet326.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 326"); shell.setLayout(new GridLayout()); final Browser browser; try {/* w w w . j a v a 2s . c o m*/ browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } browser.setLayoutData(new GridData(400, 400)); browser.setText(HTML); final Button button = new Button(shell, SWT.PUSH); button.setText("Invoke Browser.close()"); button.addListener(SWT.Selection, event -> { boolean result = browser.close(); System.out.println("was Browser disposed: " + result); if (result) { button.setEnabled(false); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet95.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);//from ww w. j ava 2 s. co 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, 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, e -> image.dispose()); Canvas canvas = new Canvas(popup, SWT.NONE); canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10); canvas.addPaintListener(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.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 {// w w w.j av a 2 s . 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:TableItemUpdateText.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 240);/*w w w. j ava 2 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(); }