List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:StackLayoutSample.java
public StackLayoutSample() { final StackLayout stackLayout = new StackLayout(); shell.setLayout(stackLayout);// w w w . j av a2 s .com for (int i = 0; i < buttons.length; i++) { buttons[i] = new Button(shell, SWT.NULL); buttons[i].setText("Button #" + i); buttons[i].addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { // Flip to next button. Button nextButton = null; for (int i = 0; i < buttons.length; i++) { if (buttons[i] == e.widget) { if (i == buttons.length - 1) nextButton = buttons[0]; else nextButton = buttons[i + 1]; } } stackLayout.topControl = nextButton; shell.layout(); } public void widgetDefaultSelected(SelectionEvent e) { } }); } // Initial stackLayout.topControl = buttons[0]; shell.setSize(200, 100); shell.open(); // 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:DialogShell.java
public DialogShell() { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout()); shell.setSize(500, 200);/* w w w. j a v a2s . c om*/ final Button openDialog = new Button(shell, SWT.PUSH); openDialog.setText("Click here to rate this book ..."); openDialog.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setLayout(new RowLayout()); final String[] ratings = new String[] { "Killer!", "Good stuff", "So-so", "Needs work" }; final Button[] radios = new Button[ratings.length]; for (int i = 0; i < ratings.length; i++) { radios[i] = new Button(dialog, SWT.RADIO); radios[i].setText(ratings[i]); } Button rateButton = new Button(dialog, SWT.PUSH); rateButton.setText("Rate!"); rateButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { for (int i = 0; i < radios.length; i++) if (radios[i].getSelection()) openDialog.setText("Rating: " + ratings[i]); dialog.close(); } public void widgetDefaultSelected(SelectionEvent e) { } }); dialog.pack(); dialog.open(); // Move the dialog to the center of the top level shell. Rectangle shellBounds = shell.getBounds(); Point dialogSize = dialog.getSize(); dialog.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2, shellBounds.y + (shellBounds.height - dialogSize.y) / 2); } public void widgetDefaultSelected(SelectionEvent e) { } }); shell.open(); // 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:RowLayoutSample.java
public RowLayoutSample() { RowLayout rowLayout = new RowLayout(); //rowLayout.fill = true; //rowLayout.justify = true; //rowLayout.pack = false; //rowLayout.type = SWT.VERTICAL; //rowLayout.wrap = false; shell.setLayout(rowLayout);/*from w w w .ja v a2 s .co m*/ Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); button1.setLayoutData(new RowData(100, 35)); List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); //shell.setSize(120, 120); shell.pack(); shell.open(); // 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:GridLayoutSampleSpan.java
public GridLayoutSampleSpan() { GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;//from w ww . ja v a 2 s .c o 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.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; button2.setLayoutData(gridData); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); GridData gridData2 = new GridData(GridData.VERTICAL_ALIGN_END); gridData2.verticalSpan = 3; button3.setLayoutData(gridData2); 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:SWTDefaultButton.java
public SWTDefaultButton() { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final String[] ratings = new String[] { "Killer!", "Good stuff", "So-so", "Needs work" }; final Button[] radios = new Button[ratings.length]; for (int i = 0; i < ratings.length; i++) { radios[i] = new Button(shell, SWT.RADIO); radios[i].setText(ratings[i]);/*from w ww.j a v a 2 s . c om*/ } Button cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Canel"); Button rateButton = new Button(shell, SWT.PUSH); rateButton.setText("Rate!"); rateButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { for (int i = 0; i < radios.length; i++) if (radios[i].getSelection()) System.out.println("Rating: " + ratings[i]); } public void widgetDefaultSelected(SelectionEvent e) { System.out.println("Default selection"); } }); shell.setDefaultButton(rateButton); System.out.println(shell.getDefaultButton()); 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:Ch6GridLayoutAllOptionsComposite.java
public Ch6GridLayoutAllOptionsComposite(Composite parent) { super(parent, SWT.NONE); int[] fillStyles = { SWT.NONE, GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, GridData.FILL_BOTH }; int[] alignStyles = { SWT.NONE, GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.HORIZONTAL_ALIGN_END, GridData.HORIZONTAL_ALIGN_CENTER, GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_END, GridData.VERTICAL_ALIGN_CENTER, GridData.VERTICAL_ALIGN_FILL }; GridLayout layout = new GridLayout(fillStyles.length, false); setLayout(layout);// ww w . j a v a 2s . co m int count = 0; for (int i = 0; i < alignStyles.length; ++i) { for (int j = 0; j < fillStyles.length; ++j) { Button button = new Button(this, SWT.NONE); button.setText("Cell " + count++); button.setLayoutData(new GridData(fillStyles[j] | alignStyles[i])); } } }
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 w w. ja v a2 s . co 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:DumbUser.java
/** * Creates the main window's contents//from w ww . j av a 2s . c om * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, true)); // Create the button Button show = new Button(composite, SWT.NONE); show.setText("Show"); final Shell shell = parent.getShell(); // Display the dialog show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create and show the dialog DumbMessageDialog dlg = new DumbMessageDialog(shell); dlg.open(); } }); parent.pack(); return composite; }
From source file:SimpleCanvas.java
/** * Creates the main window's contents// w w w. j a v a 2 s . c om * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FillLayout()); // Create a canvas Canvas canvas = new Canvas(shell, SWT.NONE); // Create a button on the canvas Button button = new Button(canvas, SWT.PUSH); button.setBounds(10, 10, 300, 40); button.setText("You can place widgets on a canvas"); // Create a paint handler for the canvas canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Do some drawing Rectangle rect = ((Canvas) e.widget).getBounds(); e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED)); e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10); e.gc.drawText("You can draw text directly on a canvas", 60, 60); } }); }
From source file:ScrolledCompositeTest.java
private void createContents(Composite parent) { parent.setLayout(new FillLayout()); // Create the ScrolledComposite to scroll horizontally and vertically ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); // Create a child composite to hold the controls Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); // Create the buttons new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); /*//from w w w. j av a2 s .c o m * // Set the absolute size of the child child.setSize(400, 400); */ // Set the child as the scrolled content of the ScrolledComposite sc.setContent(child); // Set the minimum size sc.setMinSize(400, 400); // Expand both horizontally and vertically sc.setExpandHorizontal(true); sc.setExpandVertical(true); }