List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:ScreenShotWithGC.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { /* Take the screen shot */ GC gc = new GC(display); final Image image = new Image(display, display.getBounds()); gc.copyArea(image, 0, 0);// ww w .j a v a 2 s . c om gc.dispose(); Shell popup = new Shell(shell, SWT.SHELL_TRIM); popup.setLayout(new FillLayout()); popup.setText("Image"); popup.setBounds(50, 50, 200, 200); popup.addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { image.dispose(); } }); ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL); Canvas canvas = new Canvas(sc, SWT.NONE); sc.setContent(canvas); canvas.setBounds(display.getBounds()); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); popup.open(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);/*from w w w . j a v a 2 s . c om*/ Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; composite.setLayout(gridLayout); Button two = new Button(composite, SWT.PUSH); two.setText("two"); GridData gridData = new GridData(GridData.FILL_BOTH); two.setLayoutData(gridData); Button three = new Button(composite, SWT.PUSH); three.setText("three"); gridData = new GridData(GridData.FILL_BOTH); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(one, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(100, -5); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FontDialogColorFontData.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Font Chooser"); 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) { Font font = null;// ww w. jav a 2s . c o m Color color = null; FontDialog dlg = new FontDialog(shell); if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); if (font != null) font.dispose(); if (color != null) color.dispose(); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet95.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Widget"); shell.setBounds(10, 10, 200, 200);/* w ww . ja va 2 s . c om*/ final Table table = new Table(shell, SWT.MULTI); table.setLinesVisible(true); 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.setBounds(10, 140, 50, 20); 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.setBounds(50, 50, 200, 200); popup.addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { image.dispose(); } }); Canvas canvas = new Canvas(popup, SWT.NONE); canvas.setBounds(10, 10, 150, 150); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); popup.open(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display d = new Display(); Shell s = new Shell(d); s.setSize(250, 250);//from www . j a v a 2s. c om 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:ButtonClass.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(200, 200);//w w w.j a v a2 s . c om shell.setText("Button Example"); final Button button = new Button(shell, SWT.PUSH); button.setBounds(40, 50, 50, 20); button.setText("Click Me"); final Text text = new Text(shell, SWT.BORDER); text.setBounds(100, 50, 70, 20); button.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { text.setText("No problem"); } public void widgetDefaultSelected(SelectionEvent event) { text.setText("No worries!"); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet107.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Button button1 = new Button(shell, SWT.PUSH); button1.setText("Button 1"); final Sash sash = new Sash(shell, SWT.VERTICAL); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Button 2"); final FormLayout form = new FormLayout(); shell.setLayout(form);/* w ww . j a v a2 s . c o m*/ FormData button1Data = new FormData(); button1Data.left = new FormAttachment(0, 0); button1Data.right = new FormAttachment(sash, 0); button1Data.top = new FormAttachment(0, 0); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); final int limit = 20, percent = 50; final FormData sashData = new FormData(); sashData.left = new FormAttachment(percent, 0); sashData.top = new FormAttachment(0, 0); sashData.bottom = new FormAttachment(100, 0); sash.setLayoutData(sashData); sash.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Rectangle sashRect = sash.getBounds(); Rectangle shellRect = shell.getClientArea(); int right = shellRect.width - sashRect.width - limit; e.x = Math.max(Math.min(e.x, right), limit); if (e.x != sashRect.x) { sashData.left = new FormAttachment(0, e.x); shell.layout(); } } }); FormData button2Data = new FormData(); button2Data.left = new FormAttachment(sash, 0); button2Data.right = new FormAttachment(100, 0); button2Data.top = new FormAttachment(0, 0); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet313.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 313"); shell.setLayout(new FormLayout()); final Button button = new Button(shell, SWT.PUSH); button.setText(">>"); FormData data = new FormData(); data.top = new FormAttachment(0, 4); data.right = new FormAttachment(100, -4); button.setLayoutData(data);//from w ww . j a va2 s .co m final Composite composite = new Composite(shell, SWT.BORDER); final FormData down = new FormData(); down.top = new FormAttachment(button, 4, SWT.BOTTOM); down.bottom = new FormAttachment(100, -4); down.left = new FormAttachment(0, 4); down.right = new FormAttachment(100, -4); final FormData up = new FormData(); up.top = new FormAttachment(0); up.bottom = new FormAttachment(0); up.left = new FormAttachment(0); up.right = new FormAttachment(0); composite.setLayoutData(up); button.addSelectionListener(widgetSelectedAdapter(e -> { if (composite.getLayoutData() == up) { composite.setLayoutData(down); button.setText("<<"); } else { composite.setLayoutData(up); button.setText(">>"); } shell.pack(); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ViewFormCreate.java
public static void main(String[] args) { Shell shell = new Shell(display); shell.setText("Look"); shell.setLayout(new GridLayout(1, false)); Button button = new Button(shell, SWT.PUSH); button.setText("New Document"); final Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new FillLayout()); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { createViewFormHelper(composite, "Document " + (++count)); composite.layout();/* w w w .j a va2s. co m*/ } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet167.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 167"); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300);/* w w w. j a v a 2 s.c o m*/ sc1.setContent(button1); final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = widgetSelectedAdapter(e -> { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); }); SelectionListener listener2 = widgetSelectedAdapter(e -> { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); }); vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }