List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:AsyncExecDisplay.java
public static Thread getTask2(Button button) { final Button theButton = button; return new Thread() { public void run() { try { Thread.sleep(6000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace();/*w w w. java2 s . c o m*/ } display.asyncExec(new Runnable() { public void run() { theButton.setText("done"); } }); } }; }
From source file:widgetTest3.java
/** * StackLayout ** */ public static void createStackLayout(Composite composite) { // Neues Composite erzeugen final Composite stackComposite = new Composite(composite, SWT.NULL); final StackLayout stackLayout = new StackLayout(); // Text-Buttons erzeugen final Button buttonA = new Button(stackComposite, SWT.PUSH); buttonA.setText("Taste A"); final Button buttonB = new Button(stackComposite, SWT.PUSH); buttonB.setText("Taste B"); // Auf Klickereignisse reagieren buttonA.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { stackLayout.topControl = buttonB; // Neues Layout erzwingen stackComposite.layout();/*from w w w . j a v a 2s. co m*/ // Fokus auf sichtbare Taste setzen buttonB.setFocus(); } }); buttonB.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { stackLayout.topControl = buttonA; // Neues Layout erzwingen stackComposite.layout(); // Fokus auf sichtbare Taste setzen buttonA.setFocus(); } }); // Layout initialisieren stackLayout.topControl = buttonA; stackLayout.marginWidth = 10; stackLayout.marginHeight = 5; // Layout setzen stackComposite.setLayout(stackLayout); }
From source file:widgetTest3.java
/** * Printing ** */ public static void createPrintButton(final Composite composite) { // Create button for starting printing process final Button printButton = new Button(composite, SWT.PUSH); printButton.setText("Print"); // React to clicks printButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // Get Shell instance Shell shell = composite.getShell(); // Create printer selection dialog PrintDialog printDialog = new PrintDialog(shell); // and open it PrinterData printerData = printDialog.open(); // Check if OK was pressed if (printerData != null) { // Create new Printer instance Printer printer = new Printer(printerData); // Create graphics context for this printer GC gc = new GC(printer); // Open printing task if (!printer.startJob("Hello")) System.out.println("Starting printer task failed"); else { // Print first page if (!printer.startPage()) System.out.println("Printing of page 1 failed"); else { // Get green system color from printer // and set it as text color Color green = printer.getSystemColor(SWT.COLOR_DARK_GREEN); gc.setForeground(green); // Draw text gc.drawText("Hello World", 4, 4, true); // Close page printer.endPage(); }//w w w . j av a 2 s. c om // Print second page if (!printer.startPage()) System.out.println("Printing of page 2 failed"); else { // Get blue system color from printer // and set it as text color Color blue = printer.getSystemColor(SWT.COLOR_BLUE); gc.setForeground(blue); // Draw text gc.drawText("Hello Eclipse", 4, 4, true); // Close page printer.endPage(); } // Close printing task printer.endJob(); } // Release operating system resources gc.dispose(); printer.dispose(); } } }); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); text.setLayoutData(new GridData(GridData.FILL_BOTH)); Button show = new Button(composite, SWT.PUSH); show.setText("Show Error"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Status status = new Status(IStatus.ERROR, "My Plug-in ID", 0, "Status Error Message", null); ErrorDialog.openError(Display.getCurrent().getActiveShell(), "JFace Error", text.getText(), status); }// w ww . ja v a 2 s . c o m }); return composite; }
From source file:CompViewer.java
public Ch3_Group(Composite parent) { super(parent, SWT.NONE); Group group = new Group(this, SWT.SHADOW_ETCHED_IN); group.setText("Group Label"); Label label = new Label(group, SWT.NONE); label.setText("Two buttons:"); label.setLocation(20, 20);//w ww . ja v a 2 s . c o m label.pack(); Button button1 = new Button(group, SWT.PUSH); button1.setText("Push button"); button1.setLocation(20, 45); button1.pack(); Button button2 = new Button(group, SWT.CHECK); button2.setText("Check button"); button2.setBounds(20, 75, 90, 30); group.pack(); }
From source file:ShowInputDialog.java
private void createContents(final Shell parent) { parent.setLayout(new FillLayout(SWT.VERTICAL)); final Label label = new Label(parent, SWT.NONE); Button button = new Button(parent, SWT.PUSH); button.setText("Push Me"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create and display the InputDialog InputDialog dlg = new InputDialog(parent); String input = dlg.open(); if (input != null) { // User clicked OK; set the text into the label label.setText(input);/*ww w. j av a 2s .c o m*/ label.getParent().pack(); } } }); }
From source file:MouseMoveListenerExample.java
public MouseMoveListenerExample() { d = new Display(); s = new Shell(d); s.setSize(250, 200);/* www . ja v a 2 s . c om*/ s.setText("A MouseListener Example"); final Button b = new Button(s, SWT.PUSH); b.setText("Push Me"); b.setBounds(20, 50, 55, 25); s.open(); b.addMouseMoveListener(new MouseMoveListener() { public void mouseMove(MouseEvent e) { Random r = new Random(System.currentTimeMillis()); Point p = s.getSize(); int newX = r.nextInt(p.y); int newY = r.nextInt(p.x); b.setBounds(newX - 55, newY - 25, 55, 25); } }); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MouseTrackExample.java
public MouseTrackExample() { d = new Display(); s = new Shell(d); s.setSize(250, 200);//from ww w . j a v a 2 s. co m s.setText("A MouseTrackListener Example"); final Button b = new Button(s, SWT.PUSH); b.setText("Push Me"); b.setBounds(20, 50, 55, 25); s.open(); final Color oldColor = b.getBackground(); b.addMouseTrackListener(new MouseTrackAdapter() { public void mouseEnter(MouseEvent e) { b.setBackground(new Color(d, 0, 153, 153)); } public void mouseExit(MouseEvent e) { b.setBackground(oldColor); } }); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:Ch5Composite.java
public Ch5Composite(Composite parent) { super(parent, SWT.NONE); FillLayout layout = new FillLayout(SWT.VERTICAL); setLayout(layout);//w ww .j a va2 s . c om for (int i = 0; i < 8; ++i) { Button button = new Button(this, SWT.NONE); button.setText("Sample Text"); } }
From source file:Ch6GridLayoutComposite.java
public Ch6GridLayoutComposite(Composite parent) { super(parent, SWT.NONE); GridLayout layout = new GridLayout(4, false); setLayout(layout);/* ww w.j av a 2 s . com*/ for (int i = 0; i < 16; ++i) { Button button = new Button(this, SWT.NONE); button.setText("Cell " + i); } }