List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:LayoutTerms.java
public LayoutTerms() { init();// ww w .j a v a2s. c o m Composite composite; System.out.println("Bounds: " + shell.getBounds()); System.out.println("Client area: " + shell.getClientArea()); shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); RowLayout rowLayout = new RowLayout(); rowLayout.type = SWT.HORIZONTAL; rowLayout.wrap = true; rowLayout.marginLeft = 15; rowLayout.marginTop = 5; rowLayout.marginRight = 15; rowLayout.marginBottom = 10; rowLayout.spacing = 8; shell.setLayout(rowLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button number 2"); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); shell.pack(); shell.open(); System.out.println("button1: " + button1.getBounds()); System.out.println("button2: " + button2.getBounds()); // 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:RadioButtons.java
public RadioButtons() { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NULL); label.setText("Gender: "); label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Button femaleButton = new Button(shell, SWT.RADIO); femaleButton.setText("F"); Button maleButton = new Button(shell, SWT.RADIO); maleButton.setText("M"); label = new Label(shell, SWT.NULL); label.setText(" Title: "); label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Composite composite = new Composite(shell, SWT.NULL); composite.setLayout(new RowLayout()); Button mrButton = new Button(composite, SWT.RADIO); mrButton.setText("Mr."); Button mrsButton = new Button(composite, SWT.RADIO); mrsButton.setText("Mrs."); Button msButton = new Button(composite, SWT.RADIO); msButton.setText("Ms."); Button drButton = new Button(composite, SWT.RADIO); drButton.setText("Dr."); shell.pack();/* w w w.j av a 2s. c om*/ 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:ChooseColor.java
/** * Creates the window contents//from w ww. java 2 s . c o m * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); // Start with Celtics green color = new Color(shell.getDisplay(), new RGB(0, 255, 0)); // Use a label full of spaces to show the color final Label colorLabel = new Label(shell, SWT.NONE); colorLabel.setText(" "); colorLabel.setBackground(color); Button button = new Button(shell, SWT.PUSH); button.setText("Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(shell); // Set the selected color in the dialog from // user's selected color dlg.setRGB(colorLabel.getBackground().getRGB()); // Change the title bar text dlg.setText("Choose a Color"); // Open the dialog and retrieve the selected color RGB rgb = dlg.open(); if (rgb != null) { // Dispose the old color, create the // new one, and set into the label color.dispose(); color = new Color(shell.getDisplay(), rgb); colorLabel.setBackground(color); } } }); }
From source file:ControlEditorTestTwo.java
/** * Creates the main window's contents//ww w . j a v a 2s . co m * * @param shell the main window */ private void createContents(final Shell shell) { color = new Color(shell.getDisplay(), 255, 0, 0); // Create a composite that will be the parent of the editor final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color); composite.setBounds(0, 0, 300, 100); // Create the editor ControlEditor editor = new ControlEditor(composite); // Create the control associated with the editor Button button = new Button(composite, SWT.PUSH); button.setText("Change Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ColorDialog dialog = new ColorDialog(shell); if (color != null) dialog.setRGB(color.getRGB()); RGB rgb = dialog.open(); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor along the bottom of the parent composite editor.grabHorizontal = true; editor.verticalAlignment = SWT.BOTTOM; Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumHeight = size.y; editor.setEditor(button); }
From source file:ListExample3.java
ListExample3() { d = new Display(); s = new Shell(d); s.setSize(250, 250);//w w w. ja v a 2 s. c o m s.setText("A List Example"); final List l = new List(s, SWT.MULTI | SWT.BORDER); l.setBounds(50, 50, 75, 75); l.add("Item One"); l.add("Item Two"); l.add("Item Three"); l.add("Item Four"); l.add("Item Five"); final Button b1 = new Button(s, SWT.PUSH | SWT.BORDER); b1.setBounds(150, 150, 50, 25); b1.setText("Click Me"); b1.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String selected[] = l.getSelection(); for (int i = 0; i < selected.length; i++) { System.out.println(selected[i]); } } }); 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, true)); final Button indeterminate = new Button(composite, SWT.CHECK); indeterminate.setText("Indeterminate"); Button showProgress = new Button(composite, SWT.NONE); showProgress.setText("Show Progress"); final Shell shell = parent.getShell(); 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()); }//from ww w.ja v a 2 s .co m } }); parent.pack(); return composite; }
From source file:SimpleCanvas.java
/** * Creates the main window's contents/*from w w w . jav a 2s. c o m*/ * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FillLayout()); // Create a canvas Canvas canvas = new Canvas(shell, SWT.NONE); // Create a button on the canvas Button button = new Button(canvas, SWT.PUSH); button.setBounds(10, 10, 300, 40); button.setText("You can place widgets on a canvas"); // Create a paint handler for the canvas canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Do some drawing Rectangle rect = ((Canvas) e.widget).getBounds(); e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED)); e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10); e.gc.drawText("You can draw text directly on a canvas", 60, 60); } }); }
From source file:ChooseFont.java
/** * Creates the window contents//from w w w . ja va2 s .co m * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); // Pre-fill the dialog with any previous selection if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { // Dispose of any fonts or colors we have created if (font != null) font.dispose(); if (color != null) color.dispose(); // Create the new font and set it into the label font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); // Create the new color and set it color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); // Call pack() to resize the window to fit the new font shell.pack(); } } }); }
From source file:GetInput.java
/** * Creates the main window's contents/*from ww w .ja va2s . c om*/ * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); // Create a label to display what the user typed in final Label label = new Label(composite, SWT.NONE); label.setText("This will display the user input from InputDialog"); // Create the button to launch the error dialog Button show = new Button(composite, SWT.PUSH); show.setText("Get Input"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters", label.getText(), new LengthValidator()); if (dlg.open() == Window.OK) { // User clicked OK; update the label with the input label.setText(dlg.getValue()); } } }); parent.pack(); return composite; }
From source file:RegistryTest.java
/** * Creates the window's contents//from w ww . j a v a 2 s. co m * * @param parent the parent composite * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout(SWT.VERTICAL)); // Set up the registries CR = new ColorRegistry(); CR.addListener(this); FR = new FontRegistry(); FR.addListener(this); // Create the label label = new Label(composite, SWT.CENTER); label.setText("Hello from JFace"); // Create the randomize button Button button = new Button(composite, SWT.PUSH); button.setText("Randomize"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { CR.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); CR.put(BACKGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); FontData fontData = new FontData("Times New Roman", (int) (Math.random() * 72), SWT.BOLD); FR.put(FONT, new FontData[] { fontData }); } }); return composite; }