List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:Ch12WebBrowserComposite.java
public Ch12WebBrowserComposite(Composite parent) { super(parent, SWT.NONE); GridLayout layout = new GridLayout(2, true); setLayout(layout);//from w ww.jav a 2 s . co m browser = new Browser(this, SWT.NONE); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; layoutData.verticalSpan = 2; browser.setLayoutData(layoutData); browser.setUrl("http://www.slashdot.org"); final Text text = new Text(this, SWT.SINGLE); layoutData = new GridData(GridData.FILL_HORIZONTAL); text.setLayoutData(layoutData); Button openButton = new Button(this, SWT.PUSH); openButton.setText("Open"); openButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { browser.setUrl(text.getText()); } public void widgetDefaultSelected(SelectionEvent e) { } }); Button backButton = new Button(this, SWT.PUSH); backButton.setText("Back"); backButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { browser.back(); } public void widgetDefaultSelected(SelectionEvent e) { } }); Button forwardButton = new Button(this, SWT.PUSH); forwardButton.setText("Forward"); forwardButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { browser.forward(); } public void widgetDefaultSelected(SelectionEvent e) { } }); }
From source file:GroupShellExample2.java
GroupShellExample2() { d = new Display(); s = new Shell(d); s.setSize(200, 200);/* w w w . j a v a2s . c o m*/ s.setText("A Group Example"); final Group g = new Group(s, SWT.SHADOW_ETCHED_IN); g.setSize(110, 75); g.setText("Options Group"); final Button b1; final Button b2; final Button b3; b1 = new Button(g, SWT.RADIO); b1.setBounds(10, 20, 75, 15); b1.setText("Option One"); b2 = new Button(g, SWT.RADIO); b2.setBounds(10, 35, 75, 15); b2.setText("Option Two"); b3 = new Button(g, SWT.RADIO); b3.setBounds(10, 50, 80, 15); b3.setText("Option Three"); g.pack(); g.setLocation(20, 20); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button preserveCase = new Button(composite, SWT.CHECK); preserveCase.setText("&Preserve case"); final TreeViewer tv = new TreeViewer(composite); tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tv.setContentProvider(new FileTreeContentProvider()); tv.setLabelProvider(new FileTreeLabelProvider()); tv.setInput("root"); preserveCase.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean preserveCase = ((Button) event.widget).getSelection(); FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider(); ftlp.setPreserveCase(preserveCase); }//from w w w .j a v a2 s. c om }); return composite; }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button filterButton = new Button(composite, SWT.CHECK); filterButton.setText("&Show only healthy"); final ListViewer lv = new ListViewer(composite); lv.setContentProvider(new ItemContentProvider()); lv.setLabelProvider(new ItemLabelProvider()); lv.setInput(new ItemList()); filterButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (((Button) event.widget).getSelection()) lv.addFilter(filter);//from w ww . ja v a2s. c o m else lv.removeFilter(filter); } }); parent.pack(); return composite; }
From source file:ShowProgress.java
/** * Creates the main window's contents/* ww w. ja va 2s . co m*/ * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, true)); // Create the indeterminate checkbox final Button indeterminate = new Button(composite, SWT.CHECK); indeterminate.setText("Indeterminate"); // Create the ShowProgress button Button showProgress = new Button(composite, SWT.NONE); showProgress.setText("Show Progress"); final Shell shell = parent.getShell(); // Display the ProgressMonitorDialog showProgress.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { try { new ProgressMonitorDialog(shell).run(true, true, new LongRunningOperation(indeterminate.getSelection())); } catch (InvocationTargetException e) { MessageDialog.openError(shell, "Error", e.getMessage()); } catch (InterruptedException e) { MessageDialog.openInformation(shell, "Cancelled", e.getMessage()); } } }); parent.pack(); return composite; }
From source file:FocusTraversal.java
private void init() { 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"); List list = new List(composite1, SWT.MULTI | SWT.BORDER); list.setItems(new String[] { "Item-1", "Item-2", "Item-3" }); 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"); final Canvas canvas = new Canvas(composite2, SWT.NULL); canvas.setSize(50, 50);// ww w. ja v a 2 s . co m canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0); canvas.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { GC gc = new GC(canvas); // Erase background first. Rectangle rect = canvas.getClientArea(); gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); Font font = new Font(display, "Arial", 32, SWT.BOLD); gc.setFont(font); gc.drawString("" + e.character, 15, 10); gc.dispose(); font.dispose(); } public void keyReleased(KeyEvent e) { } }); canvas.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) e.doit = true; } }); composite1.setTabList(new Control[] { button1, list }); composite2.setTabList(new Control[] { button2, canvas, combo }); shell.setTabList(new Control[] { composite2, composite1 }); }
From source file:ShowFileDialog.java
/** * Creates the contents for the window/* w w w.j a v a 2 s . c o m*/ * * @param shell the parent shell */ public void createContents(final Shell shell) { shell.setLayout(new GridLayout(5, true)); new Label(shell, SWT.NONE).setText("File Name:"); final Text fileName = new Text(shell, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; fileName.setLayoutData(data); Button multi = new Button(shell, SWT.PUSH); multi.setText("Open Multiple..."); multi.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to open multiple files FileDialog dlg = new FileDialog(shell, SWT.MULTI); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { // Append all the selected files. Since getFileNames() returns only // the names, and not the path, prepend the path, normalizing // if necessary StringBuffer buf = new StringBuffer(); String[] files = dlg.getFileNames(); for (int i = 0, n = files.length; i < n; i++) { buf.append(dlg.getFilterPath()); if (buf.charAt(buf.length() - 1) != File.separatorChar) { buf.append(File.separatorChar); } buf.append(files[i]); buf.append(" "); } fileName.setText(buf.toString()); } } }); Button open = new Button(shell, SWT.PUSH); open.setText("Open..."); open.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to open a single file FileDialog dlg = new FileDialog(shell, SWT.OPEN); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { fileName.setText(fn); } } }); Button save = new Button(shell, SWT.PUSH); save.setText("Save..."); save.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to save a file FileDialog dlg = new FileDialog(shell, SWT.SAVE); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { fileName.setText(fn); } } }); }
From source file:Ch6RadialLayoutComposite.java
public Ch6RadialLayoutComposite(Composite parent) { super(parent, SWT.NONE); setLayout(new RadialLayout()); for (int i = 0; i < 8; i++) { Button b = new Button(this, SWT.NONE); b.setText("Cell " + (i + 1)); }//from w ww . jav a2 s.com }
From source file:DumbUser.java
/** * Creates the main window's contents//from w w w. j a v a2 s .c o m * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, true)); // Create the button Button show = new Button(composite, SWT.NONE); show.setText("Show"); final Shell shell = parent.getShell(); // Display the dialog show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create and show the dialog DumbMessageDialog dlg = new DumbMessageDialog(shell); dlg.open(); } }); parent.pack(); return composite; }
From source file:SimpleBrowser.java
/** * Creates the main window's contents// w w w . j a v a 2s . com * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FormLayout()); // Create the composite to hold the buttons and text field Composite controls = new Composite(shell, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); controls.setLayoutData(data); // Create the web browser final Browser browser = new Browser(shell, SWT.NONE); data = new FormData(); data.top = new FormAttachment(controls); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); browser.setLayoutData(data); // Create the controls and wire them to the browser controls.setLayout(new GridLayout(6, false)); // Create the back button Button button = new Button(controls, SWT.PUSH); button.setText("Back"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.back(); } }); // Create the forward button button = new Button(controls, SWT.PUSH); button.setText("Forward"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.forward(); } }); // Create the refresh button button = new Button(controls, SWT.PUSH); button.setText("Refresh"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.refresh(); } }); // Create the stop button button = new Button(controls, SWT.PUSH); button.setText("Stop"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.stop(); } }); // Create the address entry field and set focus to it final Text url = new Text(controls, SWT.BORDER); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.setFocus(); // Create the go button button = new Button(controls, SWT.PUSH); button.setText("Go"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.setUrl(url.getText()); } }); // Allow users to hit enter to go to the typed URL shell.setDefaultButton(button); }