List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:RoundRectangleExample.java
/** * Creates the main window's contents//from ww w . j a v a2 s . co m * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FillLayout(SWT.VERTICAL)); // Create the composite that holds the input fields Composite widgetComposite = new Composite(shell, SWT.NONE); widgetComposite.setLayout(new GridLayout(2, false)); // Create the input fields new Label(widgetComposite, SWT.NONE).setText("Arc Width:"); txtArcWidth = new Text(widgetComposite, SWT.BORDER); new Label(widgetComposite, SWT.NONE).setText("Arc Height"); txtArcHeight = new Text(widgetComposite, SWT.BORDER); // Create the button that launches the redraw Button button = new Button(widgetComposite, SWT.PUSH); button.setText("Redraw"); shell.setDefaultButton(button); // Create the canvas to draw the round rectangle on final Canvas drawingCanvas = new Canvas(shell, SWT.NONE); drawingCanvas.addPaintListener(new RoundRectangleExamplePaintListener()); // Add a handler to redraw the round rectangle when pressed button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { drawingCanvas.redraw(); } }); }
From source file:TableShellExample3.java
TableShellExample3() { d = new Display(); s = new Shell(d); s.setSize(250, 200);//from w ww. ja va2s . c o m s.setText("A Table Shell Example"); GridLayout gl = new GridLayout(); gl.numColumns = 4; s.setLayout(gl); final Table t = new Table(s, SWT.BORDER | SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION); final GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 4; t.setLayoutData(gd); t.setHeaderVisible(true); final TableColumn tc1 = new TableColumn(t, SWT.LEFT); final TableColumn tc2 = new TableColumn(t, SWT.CENTER); final TableColumn tc3 = new TableColumn(t, SWT.CENTER); tc1.setText("First Name"); tc2.setText("Last Name"); tc3.setText("Address"); tc1.setWidth(70); tc2.setWidth(70); tc3.setWidth(80); final TableItem item1 = new TableItem(t, SWT.NONE); item1.setText(new String[] { "Tim", "Hatton", "Kentucky" }); final TableItem item2 = new TableItem(t, SWT.NONE); item2.setText(new String[] { "Caitlyn", "Warner", "Ohio" }); final TableItem item3 = new TableItem(t, SWT.NONE); item3.setText(new String[] { "Reese", "Miller", "Ohio" }); final Text find = new Text(s, SWT.SINGLE | SWT.BORDER); final Text replace = new Text(s, SWT.SINGLE | SWT.BORDER); final Button replaceBtn = new Button(s, SWT.BORDER | SWT.PUSH); replaceBtn.setText("Replace"); replaceBtn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] tia = t.getItems(); for (int i = 0; i < tia.length; i++) { if (tia[i].getText(2).equals(find.getText())) { tia[i].setText(2, replace.getText()); } } } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:InputDialog.java
private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, true)); Label label = new Label(shell, SWT.NONE); label.setText(message);/* w ww .ja v a 2 s . co m*/ GridData data = new GridData(); data.horizontalSpan = 2; label.setLayoutData(data); final Text text = new Text(shell, SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; text.setLayoutData(data); Button ok = new Button(shell, SWT.PUSH); ok.setText("OK"); data = new GridData(GridData.FILL_HORIZONTAL); ok.setLayoutData(data); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { input = text.getText(); shell.close(); } }); Button cancel = new Button(shell, SWT.PUSH); cancel.setText("Cancel"); data = new GridData(GridData.FILL_HORIZONTAL); cancel.setLayoutData(data); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { input = null; shell.close(); } }); shell.setDefaultButton(ok); }
From source file:TableShellExample2.java
TableShellExample2() { d = new Display(); s = new Shell(d); s.setSize(250, 200);//from ww w. j ava2s .com s.setText("A Table Shell Example"); GridLayout gl = new GridLayout(); gl.numColumns = 2; s.setLayout(gl); final Table t = new Table(s, SWT.BORDER | SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION); final GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; t.setLayoutData(gd); t.setHeaderVisible(true); final TableColumn tc1 = new TableColumn(t, SWT.LEFT); final TableColumn tc2 = new TableColumn(t, SWT.CENTER); final TableColumn tc3 = new TableColumn(t, SWT.CENTER); tc1.setText("First Name"); tc2.setText("Last Name"); tc3.setText("Address"); tc1.setWidth(70); tc2.setWidth(70); tc3.setWidth(80); final TableItem item1 = new TableItem(t, SWT.NONE); item1.setText(new String[] { "Tim", "Hatton", "Kentucky" }); final TableItem item2 = new TableItem(t, SWT.NONE); item2.setText(new String[] { "Caitlyn", "Warner", "Ohio" }); final TableItem item3 = new TableItem(t, SWT.NONE); item3.setText(new String[] { "Reese", "Miller", "Ohio" }); final Text input = new Text(s, SWT.SINGLE | SWT.BORDER); final Button searchBtn = new Button(s, SWT.BORDER | SWT.PUSH); searchBtn.setText("Search"); searchBtn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] tia = t.getItems(); for (int i = 0; i < tia.length; i++) { if (tia[i].getText(2).equals(input.getText())) { tia[i].setBackground(new Color(d, 127, 178, 127)); } } } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:ImageButton.java
public ImageButton() { //shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setBounds(10, 10, 200, 200);//from ww w .j a va2 s . co m button.setImage(image); button.setText("button"); System.out.println(button.getImage()); shell.pack(); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:TabFolderExample.java
public TabFolderExample() { shell.setLayout(new FillLayout()); final TabFolder tabFolder = new TabFolder(shell, SWT.BOTTOM); Button button = new Button(tabFolder, SWT.NULL); button.setText("This is a button."); TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL); tabItem1.setText("item #1"); tabItem1.setImage(icon);//from w w w. j av a 2s . com tabItem1.setControl(button); Text text = new Text(tabFolder, SWT.MULTI); text.setText("This is a text control."); TabItem tabItem2 = new TabItem(tabFolder, SWT.NULL); tabItem2.setText("item #2"); tabItem2.setImage(icon); tabItem2.setControl(text); Label label = new Label(tabFolder, SWT.NULL); label.setText("This is a text lable."); TabItem tabItem3 = new TabItem(tabFolder, SWT.NULL); tabItem3.setText("item #3"); tabItem3.setControl(label); tabFolder.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { System.out.println("Selected item index = " + tabFolder.getSelectionIndex()); System.out.println("Selected item = " + (tabFolder.getSelection() == null ? "null" : tabFolder.getSelection()[0].toString())); } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); //tabFolder.setSelection(new TabItem[]{tabItem2, tabItem3}); //tabFolder.setSelection(2); shell.setSize(400, 120); shell.open(); //textUser.forceFocus(); System.out.println(tabFolder.getSelectionIndex()); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:DialogShell.java
public DialogShell() { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout()); shell.setSize(500, 200);/*w ww . j a v a 2s .c o m*/ final Button openDialog = new Button(shell, SWT.PUSH); openDialog.setText("Click here to rate this book ..."); openDialog.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setLayout(new RowLayout()); final String[] ratings = new String[] { "Killer!", "Good stuff", "So-so", "Needs work" }; final Button[] radios = new Button[ratings.length]; for (int i = 0; i < ratings.length; i++) { radios[i] = new Button(dialog, SWT.RADIO); radios[i].setText(ratings[i]); } Button rateButton = new Button(dialog, SWT.PUSH); rateButton.setText("Rate!"); rateButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { for (int i = 0; i < radios.length; i++) if (radios[i].getSelection()) openDialog.setText("Rating: " + ratings[i]); dialog.close(); } public void widgetDefaultSelected(SelectionEvent e) { } }); dialog.pack(); dialog.open(); // Move the dialog to the center of the top level shell. Rectangle shellBounds = shell.getBounds(); Point dialogSize = dialog.getSize(); dialog.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2, shellBounds.y + (shellBounds.height - dialogSize.y) / 2); } public void widgetDefaultSelected(SelectionEvent e) { } }); shell.open(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:ShowCTabFolder.java
/** * Creates the buttons for moving the insert mark and adding a tab * /*from www. j av a 2s .co m*/ * @param composite the parent composite */ private void createButtons(Composite composite) { // Move mark left Button button = new Button(composite, SWT.PUSH); button.setText("<<"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (insertMark > -1) { --insertMark; resetInsertMark(); } } }); // Move mark right button = new Button(composite, SWT.PUSH); button.setText(">>"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (insertMark < tabFolder.getItemCount() - 1) { ++insertMark; resetInsertMark(); } } }); // Add a tab button = new Button(composite, SWT.PUSH); button.setText("Add Tab"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { new CTabItem(tabFolder, SWT.NONE, insertMark + 1).setText("Tab (" + (insertMark + 1) + ")"); } }); }
From source file:Look.java
/** * Creates the main window's contents//from w w w . j a va 2s . c o m * * @param parent the main window */ public void createContents(Composite parent) { parent.setLayout(new GridLayout(1, false)); // Pressing the "New Document" button will create a new ViewForm Button button = new Button(parent, SWT.PUSH); button.setText("New Document"); // Create the composite that holds the ViewForms final Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new FillLayout()); // Add the event handler to create the ViewForms button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { createViewFormHelper(composite, "Document " + (++count)); composite.layout(); } }); }
From source file:SimpleFileBrowser.java
private void init() { shell.setText("File Browser"); shell.setLayout(new GridLayout(1, true)); Button button = new Button(shell, SWT.PUSH); button.setText("Browse ..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NULL); String path = dialog.open(); if (path != null) { File file = new File(path); if (file.isFile()) displayFiles(new String[] { file.toString() }); else displayFiles(file.list()); }//from w ww .java2 s .c o m } }); GridData gd = new GridData(GridData.FILL_BOTH); table = new Table(shell, SWT.MULTI); table.setLayoutData(gd); // creates an image registry and adds icons to the image registry. imageRegistry = new ImageRegistry(); ImageDescriptor defaultIcon = ImageDescriptor.createFromFile(null, "java2s.gif"); imageRegistry.put("default", defaultIcon); ImageDescriptor jarIcon = ImageDescriptor.createFromFile(null, "img/jar.gif"); imageRegistry.put("jar", jarIcon); }