List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:ExpandBarControlsAdding.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 = new Image(display, "yourFile.gif"); // 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 av a 2 s . c o m*/ 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); item0.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:Snippet177.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); RowLayout layout = new RowLayout(SWT.VERTICAL); layout.wrap = true;// w w w . j ava 2 s . co m layout.fill = true; layout.justify = false; shell.setLayout(layout); Button b = new Button(shell, SWT.PUSH); b.setText("Button 1"); b = new Button(shell, SWT.PUSH); b.setText("Button 2"); b = new Button(shell, SWT.PUSH); b.setText("Button 3"); b = new Button(shell, SWT.PUSH); b.setText("Not shown"); b.setVisible(false); RowData data = new RowData(); data.exclude = true; b.setLayoutData(data); b = new Button(shell, SWT.PUSH); b.setText("Button 200 high"); data = new RowData(); data.height = 200; b.setLayoutData(data); b = new Button(shell, SWT.PUSH); b.setText("Button 200 wide"); data = new RowData(); data.width = 200; b.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet215.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 215"); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.addListener(SWT.Selection, event -> { /* Take the screen shot */ GC gc = new GC(display); final Image image = new Image(display, display.getBounds()); gc.copyArea(image, 0, 0);//from ww w . j a v a 2 s .com gc.dispose(); Shell popup = new Shell(shell, SWT.SHELL_TRIM); popup.setLayout(new FillLayout()); popup.setText("Image"); popup.setBounds(50, 50, 200, 200); popup.addListener(SWT.Close, e -> image.dispose()); ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL); Canvas canvas = new Canvas(sc, SWT.NONE); sc.setContent(canvas); canvas.setBounds(display.getBounds()); canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0)); popup.open(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet345.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(); shell.setText("Snippet 345"); shell.setLayout(new FillLayout(SWT.VERTICAL)); String string = "The quick brown fox jumps over the lazy dog"; Button button; button = new Button(shell, SWT.PUSH | SWT.WRAP); button.setText(string); button = new Button(shell, SWT.RADIO | SWT.WRAP); button.setText(string);/*from w w w . j a v a 2s . c om*/ button = new Button(shell, SWT.TOGGLE | SWT.WRAP); button.setText(string); button = new Button(shell, SWT.CHECK | SWT.WRAP); button.setText(string); shell.setSize(shell.computeSize(200, SWT.DEFAULT)); 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 w w w . j a va 2s .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(); }
From source file:TimeStopWhenButtonPressing.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.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);//from w ww . j a v a2 s . com final int time = 500; final Runnable timer = new Runnable() { 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, new Listener() { public void handleEvent(Event 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(); }
From source file:MainClass.java
public static void main(String[] a) { Display d = new Display(); Shell s = new Shell(d); s.setSize(250, 250);/* ww w . j a v a 2s . co m*/ s.setText("A RowLayout Example"); s.setLayout(new RowLayout()); final Text t = new Text(s, SWT.SINGLE | SWT.BORDER); final Button b = new Button(s, SWT.BORDER); final Button b1 = new Button(s, SWT.BORDER); b.setText("OK"); b1.setText("Cancel"); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet98.java
public static void main(String args[]) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 98"); shell.setLayout(new GridLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Push"); pageComposite = new Composite(shell, SWT.NONE); pageComposite.setLayout(new GridLayout()); pageComposite.setLayoutData(new GridData()); button.addListener(SWT.Selection, event -> { if ((pageComposite != null) && (!pageComposite.isDisposed())) { pageComposite.dispose();/*w w w . j a va 2s . c o m*/ } pageComposite = new Composite(shell, SWT.NONE); pageComposite.setLayout(new GridLayout()); pageComposite.setLayoutData(new GridData()); if (pageNum++ % 2 == 0) { Table table = new Table(pageComposite, SWT.BORDER); table.setLayoutData(new GridData()); for (int i = 0; i < 5; i++) { new TableItem(table, SWT.NONE).setText("table item " + i); } } else { new Button(pageComposite, SWT.RADIO).setText("radio"); } shell.layout(true); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutGrabExcess.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 www . j a v a 2s .c om*/ 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.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; list.setLayoutData(gridData); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); GridData gridData2 = new GridData(); gridData2.grabExcessVerticalSpace = true; gridData2.grabExcessHorizontalSpace = true; gridData2.verticalAlignment = GridData.FILL; gridData2.horizontalAlignment = 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:FocusListenerExample.java
/** * The application entry point// www . jav a 2 s. c om * * @param args the command line arguments */ public static void main(String[] args) { // Create the shell Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(3, true)); shell.setText("One Potato, Two Potato"); // Create the focus listener FocusListener listener = new FocusListener() { public void focusGained(FocusEvent event) { Button button = (Button) event.getSource(); button.setText("I'm It!"); } public void focusLost(FocusEvent event) { Button button = (Button) event.getSource(); button.setText("Pick Me!"); } }; // Create the buttons and add the listener to each one for (int i = 0; i < 6; i++) { Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); button.setText("Pick Me!"); button.addFocusListener(listener); } // Display the window shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }