List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:Snippet118.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(150, 150);//ww w . jav a2 s.c o m final Cursor[] cursor = new Cursor[1]; Button button = new Button(shell, SWT.PUSH); button.setText("Change cursor"); Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); button.setSize(size); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { FileDialog dialog = new FileDialog(shell); dialog.setFilterExtensions(new String[] { "*.ico", "*.gif", "*.*" }); String name = dialog.open(); if (name == null) return; ImageData image = new ImageData(name); Cursor oldCursor = cursor[0]; cursor[0] = new Cursor(display, image, 0, 0); shell.setCursor(cursor[0]); if (oldCursor != null) oldCursor.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (cursor[0] != null) cursor[0].dispose(); display.dispose(); }
From source file:CoolBarComposite.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); CoolBar coolBar = new CoolBar(shell, SWT.BORDER); coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final CoolItem item = new CoolItem(coolBar, SWT.DROP_DOWN); Composite c = new Composite(coolBar, SWT.NONE); c.setLayout(new GridLayout(1, false)); new Button(c, SWT.PUSH).setText("Button One"); new Button(c, SWT.PUSH).setText("Button Two"); item.setControl(c);/*from w ww.ja v a2 s . c o m*/ Control control = item.getControl(); Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); pt = item.computeSize(pt.x, pt.y); item.setSize(pt); coolBar.pack(); 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 w w .j a v a 2s . co 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:Snippet63.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.pack();//from w ww .j ava 2 s . c o m shell.open(); final boolean[] result = new boolean[1]; final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setLayout(new RowLayout()); final Button ok = new Button(dialog, SWT.PUSH); ok.setText("Ok"); Button cancel = new Button(dialog, SWT.PUSH); cancel.setText("Cancel"); Listener listener = new Listener() { public void handleEvent(Event event) { result[0] = event.widget == ok; dialog.close(); } }; ok.addListener(SWT.Selection, listener); cancel.addListener(SWT.Selection, listener); dialog.pack(); dialog.open(); System.out.println("Prompt ..."); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } System.out.println("Result: " + result[0]); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet71.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.pack();//from w ww. j av a2s. com shell.open(); Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); Label label = new Label(dialog, SWT.NONE); label.setText("Exit the application?"); Button okButton = new Button(dialog, SWT.PUSH); okButton.setText("&OK"); Button cancelButton = new Button(dialog, SWT.PUSH); cancelButton.setText("&Cancel"); FormLayout form = new FormLayout(); form.marginWidth = form.marginHeight = 8; dialog.setLayout(form); FormData okData = new FormData(); okData.top = new FormAttachment(label, 8); okButton.setLayoutData(okData); FormData cancelData = new FormData(); cancelData.left = new FormAttachment(okButton, 8); cancelData.top = new FormAttachment(okButton, 0, SWT.TOP); cancelButton.setLayoutData(cancelData); dialog.setDefaultButton(okButton); dialog.pack(); dialog.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet21.java
public static void main(String[] args) { Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); Button b = new Button(shell, SWT.PUSH); b.setBounds(10, 10, 100, 32);// w ww . j a v a 2 s. co m b.setText("Button"); shell.setDefaultButton(b); final Canvas c = new Canvas(shell, SWT.BORDER); c.setBounds(10, 50, 100, 32); c.addListener(SWT.Traverse, new Listener() { public void handleEvent(Event e) { switch (e.detail) { /* Do tab group traversal */ case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: case SWT.TRAVERSE_PAGE_NEXT: case SWT.TRAVERSE_PAGE_PREVIOUS: e.doit = true; break; } } }); c.addListener(SWT.FocusIn, new Listener() { public void handleEvent(Event e) { c.setBackground(red); } }); c.addListener(SWT.FocusOut, new Listener() { public void handleEvent(Event e) { c.setBackground(blue); } }); c.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event e) { System.out.println("KEY"); for (int i = 0; i < 64; i++) { Color c1 = red, c2 = blue; if (c.isFocusControl()) { c1 = blue; c2 = red; } c.setBackground(c1); c.update(); c.setBackground(c2); } } }); Text t = new Text(shell, SWT.SINGLE | SWT.BORDER); t.setBounds(10, 85, 100, 32); Text r = new Text(shell, SWT.MULTI | SWT.BORDER); r.setBounds(10, 120, 100, 32); c.setFocus(); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet5.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // this button is always 400 x 400. Scrollbars appear if the window is // resized to be // too small to show part of the button ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b1 = new Button(c1, SWT.PUSH); b1.setText("fixed size button"); b1.setSize(400, 400);//from w w w. j a v a2 s . c om c1.setContent(b1); // this button has a minimum size of 400 x 400. If the window is resized // to be big // enough to show more than 400 x 400, the button will grow in size. If // the window // is made too small to show 400 x 400, scrollbars will appear. ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button b2 = new Button(c2, SWT.PUSH); b2.setText("expanding button"); c2.setContent(b2); c2.setExpandHorizontal(true); c2.setExpandVertical(true); c2.setMinWidth(400); c2.setMinHeight(400); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell shell = new Shell(d); shell.setSize(250, 200);//from w w w . ja v a2s .com shell.setLayout(new GridLayout(1, false)); Composite buttonBar = new Composite(shell, SWT.NONE); buttonBar.setLayout(new RowLayout()); Button flip = new Button(buttonBar, SWT.PUSH); flip.setText("Switch Orientation"); Button weights = new Button(buttonBar, SWT.PUSH); weights.setText("Restore Weights"); Composite sash = new Composite(shell, SWT.NONE); sash.setLayout(new FillLayout()); sash.setLayoutData(new GridData(GridData.FILL_BOTH)); final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL); sashForm.SASH_WIDTH = 5; sashForm.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE)); final Button one = new Button(sashForm, SWT.PUSH); one.setText("One"); final Button two = new Button(sashForm, SWT.PUSH); two.setText("Two"); final Button three = new Button(sashForm, SWT.PUSH); three.setText("Three"); sashForm.setWeights(new int[] { 2, 2, 2 }); flip.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { switch (sashForm.getOrientation()) { case SWT.HORIZONTAL: sashForm.setOrientation(SWT.VERTICAL); break; case SWT.VERTICAL: sashForm.setOrientation(SWT.HORIZONTAL); break; } } }); weights.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { sashForm.setWeights(new int[] { 2, 2, 2 }); } }); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); // Create the main window Shell mainShell = new Shell(display); final Shell childShell = new Shell(mainShell); childShell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent event) { System.out.println("Gotcha"); }/* w w w. j a v a 2s .co m*/ }); childShell.setLayout(new FillLayout()); childShell.setText("little brother"); Button button = new Button(childShell, SWT.PUSH); button.setText("Close Me!"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { childShell.close(); } }); childShell.open(); while (!mainShell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:TabItemWithComposite.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER); for (int i = 0; i < 6; i++) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("TabItem " + i); item.setToolTipText("This is my tab" + i); item.setImage(new Image(display, "yourFile.gif")); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new FillLayout()); new Button(composite, SWT.PUSH).setText("Button One"); new Button(composite, SWT.PUSH).setText("Button Two"); new Button(composite, SWT.PUSH).setText("Button Three"); item.setControl(composite);//from ww w. ja v a2 s. c o m } tabFolder.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }