List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:ListExample3.java
ListExample3() { d = new Display(); s = new Shell(d); s.setSize(250, 250);// w w w. j a va 2 s. com 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: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)); }/* w ww . jav a 2 s . c o m*/ }
From source file:org.eclipse.swt.snippets.Snippet366.java
private static void makeOrientationGroup() { Group orientationGroup = new Group(shell, SWT.None); orientationGroup.setLayout(new RowLayout()); orientationGroup.setText("Orientation group"); final AtomicInteger prevDir = new AtomicInteger(0); final Button alignmentButton = new Button(orientationGroup, SWT.ARROW | SWT.RIGHT); alignmentButton.addListener(SWT.MouseDown, event -> { switch (prevDir.get()) { case 0:// w w w. j av a 2 s . com alignmentButton.setOrientation(SWT.LEFT_TO_RIGHT); prevDir.set(1); break; case 1: alignmentButton.setOrientation(SWT.RIGHT_TO_LEFT); prevDir.set(0); break; default: break; } }); }
From source file:ColorDialogExample.java
ColorDialogExample() { d = new Display(); s = new Shell(d); s.setSize(400, 400);//from w w w. j a va2 s . co m s.setText("A ColorDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Color"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { ColorDialog cd = new ColorDialog(s); cd.setText("ColorDialog Demo"); cd.setRGB(new RGB(255, 255, 255)); RGB newColor = cd.open(); if (newColor == null) { return; } t.setBackground(new Color(d, newColor)); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:FormLayoutSample.java
public FormLayoutSample() { shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); FormData formData = new FormData(); formData.left = new FormAttachment(20); formData.top = new FormAttachment(20); button1.setLayoutData(formData);/* w w w. j a va2 s .com*/ Button button2 = new Button(shell, SWT.PUSH); button2.setText("button number 2"); formData = new FormData(); formData.left = new FormAttachment(button1, 0, SWT.CENTER); formData.top = new FormAttachment(button1, 0, SWT.CENTER); button2.setLayoutData(formData); // Button button3 = new Button(shell, SWT.PUSH); // button3.setText("3"); // // formData = new FormData(); // formData.top = new FormAttachment(button2, 10); // formData.left = new FormAttachment(button2, 0, SWT.LEFT); // button3.setLayoutData(formData); shell.pack(); //shell.setSize(500, 600); shell.open(); //textUser.forceFocus(); //System.out.println("Button3: " + button3.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: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);/*from w w w . j a v a 2 s. co m*/ label.getParent().pack(); } } }); }
From source file:FontDialogExample.java
FontDialogExample() { d = new Display(); s = new Shell(d); s.setSize(400, 400);//from w w w . j av a2s .c om s.setText("A FontDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Font"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:GridLayoutSample.java
public GridLayoutSample() { GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;/*w w w. j a v a2 s . co m*/ gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); button1.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END); gridData.horizontalIndent = 5; button2.setLayoutData(gridData); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); button3.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); shell.pack(); 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: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 w w . ja v a2 s. com }); return composite; }
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. ja v a2 s .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(); }