List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:ShowFileDialog.java
/** * Creates the contents for the window// ww w . j a v a2 s.co m * * @param shell the parent shell */ public void createContents(final Shell shell) { shell.setLayout(new GridLayout(5, true)); new Label(shell, SWT.NONE).setText("File Name:"); final Text fileName = new Text(shell, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; fileName.setLayoutData(data); Button multi = new Button(shell, SWT.PUSH); multi.setText("Open Multiple..."); multi.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to open multiple files FileDialog dlg = new FileDialog(shell, SWT.MULTI); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { // Append all the selected files. Since getFileNames() returns only // the names, and not the path, prepend the path, normalizing // if necessary StringBuffer buf = new StringBuffer(); String[] files = dlg.getFileNames(); for (int i = 0, n = files.length; i < n; i++) { buf.append(dlg.getFilterPath()); if (buf.charAt(buf.length() - 1) != File.separatorChar) { buf.append(File.separatorChar); } buf.append(files[i]); buf.append(" "); } fileName.setText(buf.toString()); } } }); Button open = new Button(shell, SWT.PUSH); open.setText("Open..."); open.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to open a single file FileDialog dlg = new FileDialog(shell, SWT.OPEN); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { fileName.setText(fn); } } }); Button save = new Button(shell, SWT.PUSH); save.setText("Save..."); save.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to save a file FileDialog dlg = new FileDialog(shell, SWT.SAVE); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { fileName.setText(fn); } } }); }
From source file:TableShellExample2.java
TableShellExample2() { d = new Display(); s = new Shell(d); s.setSize(250, 200);/*from w w w .j a va2 s . c o m*/ s.setText("A Table Shell Example"); GridLayout gl = new GridLayout(); gl.numColumns = 2; s.setLayout(gl); final Table t = new Table(s, SWT.BORDER | SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION); final GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; t.setLayoutData(gd); t.setHeaderVisible(true); final TableColumn tc1 = new TableColumn(t, SWT.LEFT); final TableColumn tc2 = new TableColumn(t, SWT.CENTER); final TableColumn tc3 = new TableColumn(t, SWT.CENTER); tc1.setText("First Name"); tc2.setText("Last Name"); tc3.setText("Address"); tc1.setWidth(70); tc2.setWidth(70); tc3.setWidth(80); final TableItem item1 = new TableItem(t, SWT.NONE); item1.setText(new String[] { "Tim", "Hatton", "Kentucky" }); final TableItem item2 = new TableItem(t, SWT.NONE); item2.setText(new String[] { "Caitlyn", "Warner", "Ohio" }); final TableItem item3 = new TableItem(t, SWT.NONE); item3.setText(new String[] { "Reese", "Miller", "Ohio" }); final Text input = new Text(s, SWT.SINGLE | SWT.BORDER); final Button searchBtn = new Button(s, SWT.BORDER | SWT.PUSH); searchBtn.setText("Search"); searchBtn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] tia = t.getItems(); for (int i = 0; i < tia.length; i++) { if (tia[i].getText(2).equals(input.getText())) { tia[i].setBackground(new Color(d, 127, 178, 127)); } } } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:ControlSizeLocation.java
private void init() { GridLayout gridLayout = new GridLayout(2, true); shell.setLayout(gridLayout);//www . j a va 2s. co m Composite left = new Composite(shell, SWT.NULL); left.setLayout(new GridLayout()); //left.setLayout(new FillLayout()); left.setLayoutData(new GridData(GridData.FILL_BOTH)); left.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); button = new Button(left, SWT.PUSH); button.setText("Button"); button.setLayoutData(new GridData()); Composite right = new Composite(shell, SWT.NULL); right.setLayout(new GridLayout(4, true)); right.setLayoutData(new GridData(GridData.FILL_BOTH)); Label label = new Label(right, SWT.NULL); label.setText("X"); label = new Label(right, SWT.NULL); label.setText("Y"); label = new Label(right, SWT.NULL); label.setText("Width"); label = new Label(right, SWT.NULL); label.setText("Height"); x = new Text(right, SWT.BORDER); y = new Text(right, SWT.BORDER); w = new Text(right, SWT.BORDER); h = new Text(right, SWT.BORDER); SelectionListener selectionListener = new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b == get) { System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); } else if (b == set) { int vx = getNumber(x); int vy = getNumber(y); int vw = getNumber(w); int vh = getNumber(h); if (vx != -1 && vy != -1) { if (vw != -1 && vh != -1) { Rectangle rectangle = new Rectangle(vx, vy, vw, vh); button.setBounds(rectangle); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setBounds: " + rectangle); } else { Point point = new Point(vx, vy); button.setLocation(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setLocation: " + point); } } else if (vw != -1 && vh != -1) { Point point = new Point(vw, vh); button.setSize(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setSize: " + point); } } } public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }; get = new Button(right, SWT.PUSH); get.setText("Get"); get.addSelectionListener(selectionListener); set = new Button(right, SWT.PUSH); set.setText("Set"); set.addSelectionListener(selectionListener); }
From source file:InputDialog.java
private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, true)); Label label = new Label(shell, SWT.NONE); label.setText(message);/* ww w. j ava2s . c om*/ GridData data = new GridData(); data.horizontalSpan = 2; label.setLayoutData(data); final Text text = new Text(shell, SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; text.setLayoutData(data); Button ok = new Button(shell, SWT.PUSH); ok.setText("OK"); data = new GridData(GridData.FILL_HORIZONTAL); ok.setLayoutData(data); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { input = text.getText(); shell.close(); } }); Button cancel = new Button(shell, SWT.PUSH); cancel.setText("Cancel"); data = new GridData(GridData.FILL_HORIZONTAL); cancel.setLayoutData(data); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { input = null; shell.close(); } }); shell.setDefaultButton(ok); }
From source file:org.eclipse.swt.examples.controlexample.ButtonTab.java
/** * Creates the "Control" group./* w w w .jav a 2s.c o m*/ */ @Override void createControlGroup() { super.createControlGroup(); /* Create the controls */ upButton = new Button(alignmentGroup, SWT.RADIO); upButton.setText(ControlExample.getResourceString("Up")); downButton = new Button(alignmentGroup, SWT.RADIO); downButton.setText(ControlExample.getResourceString("Down")); /* Add the listeners */ SelectionListener selectionListener = widgetSelectedAdapter(event -> { if (!((Button) event.widget).getSelection()) return; setExampleWidgetAlignment(); }); upButton.addSelectionListener(selectionListener); downButton.addSelectionListener(selectionListener); }
From source file:CheckFileTree.java
/** * Creates the main window's contents//from ww w.j av a2 s. com * * @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)); // Add a checkbox to toggle whether the labels preserve case Button preserveCase = new Button(composite, SWT.CHECK); preserveCase.setText("&Preserve case"); // Create the tree viewer to display the file tree final CheckboxTreeViewer tv = new CheckboxTreeViewer(composite); tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tv.setContentProvider(new FileTreeContentProvider()); tv.setLabelProvider(new FileTreeLabelProvider()); tv.setInput("root"); // pass a non-null that will be ignored // When user checks the checkbox, toggle the preserve case attribute // of the label provider preserveCase.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean preserveCase = ((Button) event.widget).getSelection(); FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider(); ftlp.setPreserveCase(preserveCase); } }); // When user checks a checkbox in the tree, check all its children tv.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { // If the item is checked . . . if (event.getChecked()) { // . . . check all its children tv.setSubtreeChecked(event.getElement(), true); } } }); return composite; }
From source file:FoodList.java
/** * Creates the main window's contents/* w ww . ja v a 2 s. c o m*/ * * @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)); // Add a checkbox to toggle filter Button filterHealthy = new Button(composite, SWT.CHECK); filterHealthy.setText("&Show only healthy"); final ListViewer lv = new ListViewer(composite); lv.setContentProvider(new FoodContentProvider()); lv.setLabelProvider(new FoodLabelProvider()); lv.setInput(new GroceryList()); // When user checks the checkbox, toggle the filter filterHealthy.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (((Button) event.widget).getSelection()) lv.addFilter(filter); else lv.removeFilter(filter); } }); parent.pack(); return composite; }
From source file:BugReport.java
public BugReport() { shell.setLayout(new GridLayout(1, true)); shell.setImage(new Image(display, "java2s.gif")); shell.setText("Bug report page"); Group groupBug = new Group(shell, SWT.NULL); groupBug.setText("Bug details"); groupBug.setLayout(new GridLayout(2, false)); groupBug.setLayoutData(new GridData(GridData.FILL_BOTH)); new Label(groupBug, SWT.NULL).setText("Priority"); Combo combo = new Combo(groupBug, SWT.BORDER); combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(groupBug, SWT.NULL).setText("Details"); Text text = new Text(groupBug, SWT.BORDER | SWT.MULTI); text.setLayoutData(new GridData(GridData.FILL_BOTH)); Group groupProxy = new Group(shell, SWT.NULL); groupProxy.setText("Connection setting"); groupProxy.setLayout(new GridLayout(2, false)); groupProxy.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(groupProxy, SWT.NULL).setText("Proxy host"); Text textHost = new Text(groupProxy, SWT.SINGLE | SWT.BORDER); textHost.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(groupProxy, SWT.NULL).setText("Proxy port"); Text textPort = new Text(groupProxy, SWT.SINGLE | SWT.BORDER); textPort.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); //button.setAlignment(SWT.CENTER); button.setText("Submit bug report"); shell.pack();// w w w .ja v a 2s. c o m 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)); Button newPerson = new Button(composite, SWT.PUSH); newPerson.setText("Create New Person"); final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION); tv.setContentProvider(new PersonContentProvider()); tv.setLabelProvider(new StudentLabelProvider()); tv.setInput(studentList);/*from w w w .ja v a 2s . c o m*/ Table table = tv.getTable(); table.setLayoutData(new GridData(GridData.FILL_BOTH)); new TableColumn(table, SWT.CENTER).setText(NAME); new TableColumn(table, SWT.CENTER).setText(MALE); new TableColumn(table, SWT.CENTER).setText(AGE); new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR); for (int i = 0, n = table.getColumnCount(); i < n; i++) { table.getColumn(i).pack(); } table.setHeaderVisible(true); table.setLinesVisible(true); newPerson.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Student p = new Student(); p.setName("Name"); p.setMale(true); p.setAgeRange(Integer.valueOf("0")); p.setShirtColor(new RGB(255, 0, 0)); studentList.add(p); tv.refresh(); } }); CellEditor[] editors = new CellEditor[4]; editors[0] = new TextCellEditor(table); editors[1] = new CheckboxCellEditor(table); editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES, SWT.READ_ONLY); editors[3] = new ColorCellEditor(table); tv.setColumnProperties(PROPS); tv.setCellModifier(new StudentCellModifier(tv)); tv.setCellEditors(editors); return composite; }
From source file:org.eclipse.swt.examples.addressbook.DataEntryDialog.java
private void createControlButtons() { Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); GridLayout layout = new GridLayout(); layout.numColumns = 2;//from w ww . j ava 2 s . co m composite.setLayout(layout); Button okButton = new Button(composite, SWT.PUSH); okButton.setText(resAddressBook.getString("OK")); okButton.addSelectionListener(widgetSelectedAdapter(e -> shell.close())); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText(resAddressBook.getString("Cancel")); cancelButton.addSelectionListener(widgetSelectedAdapter(e -> { values = null; shell.close(); })); shell.setDefaultButton(okButton); }