List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:ScrollWidgetViewFocusIn.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Button b1 = new Button(shell, SWT.PUSH); b1.setText("top"); b1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Composite c = new Composite(sc, SWT.NONE); c.setLayout(new GridLayout(10, true)); for (int i = 0; i < 300; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); }//from ww w . j a va2 s.c o m Button b2 = new Button(shell, SWT.PUSH); b2.setText("bottom"); b2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); Listener listener = new Listener() { public void handleEvent(Event e) { Control child = (Control) e.widget; Rectangle bounds = child.getBounds(); Rectangle area = sc.getClientArea(); Point origin = sc.getOrigin(); if (origin.x > bounds.x) origin.x = Math.max(0, bounds.x); if (origin.y > bounds.y) origin.y = Math.max(0, bounds.y); if (origin.x + area.width < bounds.x + bounds.width) origin.x = Math.max(0, bounds.x + bounds.width - area.width); if (origin.y + area.height < bounds.y + bounds.height) origin.y = Math.max(0, bounds.y + bounds.height - area.height); sc.setOrigin(origin); } }; Control[] controls = c.getChildren(); for (int i = 0; i < controls.length; i++) { controls[i].addListener(SWT.Activate, listener); } shell.setSize(300, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CaptureWidgetImageGC.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. ja va 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, new Listener() { public void handleEvent(Event 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, new Listener() { public void handleEvent(Event e) { image.dispose(); } }); Canvas canvas = new Canvas(popup, SWT.NONE); canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent 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.Snippet106.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 106"); shell.setLayout(new RowLayout(SWT.VERTICAL)); final Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setHeaderVisible(true);//from ww w .j av a 2 s .c o m for (int i = 0; i < 4; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText("Column " + i); } final TableColumn[] columns = table.getColumns(); for (int i = 0; i < 12; i++) { TableItem item = new TableItem(table, SWT.NONE); for (int j = 0; j < columns.length; j++) { item.setText(j, "Item " + i); } } for (int i = 0; i < columns.length; i++) columns[i].pack(); Button button = new Button(shell, SWT.PUSH); final int index = 1; button.setText("Insert Column " + index + "a"); button.addListener(SWT.Selection, e -> { TableColumn column = new TableColumn(table, SWT.NONE, index); column.setText("Column " + index + "a"); TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { items[i].setText(index, "Item " + i + "a"); } column.pack(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ClipBoardCopyPaster.java
public static void main(String[] args) { Display display = new Display(); final Clipboard cb = new Clipboard(display); final Shell shell = new Shell(display); final Text text = new Text(shell, SWT.BORDER | SWT.SINGLE); text.setBounds(5, 5, 100, 20);/*from w ww . j a va2 s . co m*/ Button copy = new Button(shell, SWT.PUSH); copy.setBounds(5, 50, 100, 20); copy.setText("Copy"); copy.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String textData = text.getSelectionText(); if (textData.length() > 0) { TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer }); } } }); Button paste = new Button(shell, SWT.PUSH); paste.setBounds(5, 90, 100, 20); paste.setText("Paste"); paste.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { TextTransfer transfer = TextTransfer.getInstance(); String data = (String) cb.getContents(transfer); if (data != null) { text.insert(data); } } }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cb.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet130.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 130"); shell.setLayout(new GridLayout()); final Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); text.setLayoutData(new GridData(GridData.FILL_BOTH)); final int[] nextId = new int[1]; Button b = new Button(shell, SWT.PUSH); b.setText("invoke long running job"); b.addSelectionListener(widgetSelectedAdapter(e -> { Runnable longJob = new Runnable() { boolean done = false; int id; @Override/*from w ww .j ava2 s. c om*/ public void run() { Thread thread = new Thread(() -> { id = nextId[0]++; display.syncExec(() -> { if (text.isDisposed()) return; text.append("\nStart long running task " + id); }); for (int i = 0; i < 100000; i++) { if (display.isDisposed()) return; System.out.println("do task that takes a long time in a separate thread " + id); } if (display.isDisposed()) return; display.syncExec(() -> { if (text.isDisposed()) return; text.append("\nCompleted long running task " + id); }); done = true; display.wake(); }); thread.start(); while (!done && !shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }; BusyIndicator.showWhile(display, longJob); })); shell.setSize(250, 150); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } 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 w w w . j av a 2s . co m*/ 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.Snippet65.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 65"); Label label = new Label(shell, SWT.WRAP); label.setText("This is a long text string that will wrap when the dialog is resized."); List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); list.setItems("Item 1", "Item 2"); Button button1 = new Button(shell, SWT.PUSH); button1.setText("OK"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Cancel"); final int insetX = 4, insetY = 4; FormLayout formLayout = new FormLayout(); formLayout.marginWidth = insetX;//from ww w .j av a 2s .co m formLayout.marginHeight = insetY; shell.setLayout(formLayout); Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT); final FormData labelData = new FormData(size.x, SWT.DEFAULT); labelData.left = new FormAttachment(0, 0); labelData.right = new FormAttachment(100, 0); label.setLayoutData(labelData); shell.addListener(SWT.Resize, e -> { Rectangle rect = shell.getClientArea(); labelData.width = rect.width - insetX * 2; shell.layout(); }); FormData button2Data = new FormData(); button2Data.right = new FormAttachment(100, -insetX); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); FormData button1Data = new FormData(); button1Data.right = new FormAttachment(button2, -insetX); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); FormData listData = new FormData(); listData.left = new FormAttachment(0, 0); listData.right = new FormAttachment(100, 0); listData.top = new FormAttachment(label, insetY); listData.bottom = new FormAttachment(button2, -insetY); list.setLayoutData(listData); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:EventTypeGet.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Button button = new Button(shell, SWT.NONE); button.setText("Click and check the console"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { System.out.println(getEventName(e.type)); switch (e.type) { case SWT.Selection: System.out.println("Button pressed"); break; }//from w w w. ja va2s .c om } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:org.eclipse.swt.snippets.Snippet266.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 266"); shell.setLayout(new GridLayout(2, true)); TabFolder tabFolder = new TabFolder(shell, SWT.NONE); tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("Widget"); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new GridLayout()); Tree tree = new Tree(composite, SWT.BORDER); item.setControl(composite);/*from ww w . j a v a 2 s . c om*/ tree.setHeaderVisible(true); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TreeColumn column1 = new TreeColumn(tree, SWT.NONE); column1.setText("Standard"); TreeColumn column2 = new TreeColumn(tree, SWT.NONE); column2.setText("Widget"); TreeItem branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Efficient", "Portable" }); TreeItem leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch.setExpanded(true); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Native", "Controls" }); leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Cross", "Platform" }); column1.pack(); column2.pack(); item = new TabItem(tabFolder, SWT.NONE); item.setText("Toolkit"); Button button = new Button(shell, SWT.CHECK); button.setText("Totally"); button.setSelection(true); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); button = new Button(shell, SWT.PUSH); button.setText("Awesome"); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet103.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 240);/*from ww w .j a v a 2s.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.setBounds(10, 180, 50, 30); button.setText("Change"); 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(); }