List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:LayoutTerms.java
public LayoutTerms() { init();// ww w .j a va 2 s . com Composite composite; System.out.println("Bounds: " + shell.getBounds()); System.out.println("Client area: " + shell.getClientArea()); shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); RowLayout rowLayout = new RowLayout(); rowLayout.type = SWT.HORIZONTAL; rowLayout.wrap = true; rowLayout.marginLeft = 15; rowLayout.marginTop = 5; rowLayout.marginRight = 15; rowLayout.marginBottom = 10; rowLayout.spacing = 8; shell.setLayout(rowLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button number 2"); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); shell.pack(); shell.open(); System.out.println("button1: " + button1.getBounds()); System.out.println("button2: " + button2.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:Ch12WebBrowserComposite.java
public Ch12WebBrowserComposite(Composite parent) { super(parent, SWT.NONE); GridLayout layout = new GridLayout(2, true); setLayout(layout);/* ww w. j av a 2s . c o m*/ browser = new Browser(this, SWT.NONE); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; layoutData.verticalSpan = 2; browser.setLayoutData(layoutData); browser.setUrl("http://www.slashdot.org"); final Text text = new Text(this, SWT.SINGLE); layoutData = new GridData(GridData.FILL_HORIZONTAL); text.setLayoutData(layoutData); Button openButton = new Button(this, SWT.PUSH); openButton.setText("Open"); openButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { browser.setUrl(text.getText()); } public void widgetDefaultSelected(SelectionEvent e) { } }); Button backButton = new Button(this, SWT.PUSH); backButton.setText("Back"); backButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { browser.back(); } public void widgetDefaultSelected(SelectionEvent e) { } }); Button forwardButton = new Button(this, SWT.PUSH); forwardButton.setText("Forward"); forwardButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { browser.forward(); } public void widgetDefaultSelected(SelectionEvent e) { } }); }
From source file:org.eclipse.swt.snippets.Snippet237.java
static void createChildren(Composite parent) { parent.setLayout(new RowLayout()); List list = new List(parent, SWT.BORDER | SWT.MULTI); list.add("List item 1"); list.add("List item 2"); Label label = new Label(parent, SWT.NONE); label.setText("Label"); Button button = new Button(parent, SWT.RADIO); button.setText("Radio Button"); button = new Button(parent, SWT.CHECK); button.setText("Check box Button"); button = new Button(parent, SWT.PUSH); button.setText("Push Button"); Text text = new Text(parent, SWT.BORDER); text.setText("Text"); }
From source file:SashFormAdvanced.java
/** * Creates the main window's contents/*from w w w.j a v a 2 s . c om*/ * * @param parent the parent window */ private void createContents(Composite parent) { // Our layout will have a row of buttons, and // then a SashForm below it. parent.setLayout(new GridLayout(1, false)); // Create the row of buttons Composite buttonBar = new Composite(parent, 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"); // Create the SashForm Composite sash = new Composite(parent, SWT.NONE); sash.setLayout(new FillLayout()); sash.setLayoutData(new GridData(GridData.FILL_BOTH)); final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL); // Change the width of the sashes sashForm.SASH_WIDTH = 20; // Change the color used to paint the sashes sashForm.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN)); // Create the buttons and their event handlers final Button one = new Button(sashForm, SWT.PUSH); one.setText("One"); one.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(one, sashForm); } }); final Button two = new Button(sashForm, SWT.PUSH); two.setText("Two"); two.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(two, sashForm); } }); final Button three = new Button(sashForm, SWT.PUSH); three.setText("Three"); three.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(three, sashForm); } }); // Set the relative weights for the buttons sashForm.setWeights(new int[] { 1, 2, 3 }); // Add the Switch Orientation functionality 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; } } }); // Add the Restore Weights functionality weights.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { sashForm.setWeights(new int[] { 1, 2, 3 }); } }); }
From source file:ChooseFont.java
/** * Creates the window contents/*from w w w.j a v a 2 s . c o m*/ * * @param shell the parent shell */ private void createContents(final Shell shell) { 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) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); // Pre-fill the dialog with any previous selection if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { // Dispose of any fonts or colors we have created if (font != null) font.dispose(); if (color != null) color.dispose(); // Create the new font and set it into the label font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); // Create the new color and set it color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); // Call pack() to resize the window to fit the new font shell.pack(); } } }); }
From source file:FormattedText.java
public FormattedText() { label = new Label(shell, SWT.BORDER | SWT.WRAP); label.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); label.setText("Java UI Programming with SWT/JFace"); buttonColor = new Button(shell, SWT.PUSH); buttonColor.setText("Change color"); buttonColor.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { ColorDialog colorDialog = new ColorDialog(shell); if (color != null) colorDialog.setRGB(color.getRGB()); RGB value = colorDialog.open(); if (value != null) { if (color != null) color.dispose();/*from ww w . ja v a 2 s . c o m*/ color = new Color(display, value); label.setForeground(color); } else { System.out.println("Setting foreground color action canceled."); } } }); buttonFont = new Button(shell, SWT.PUSH); buttonFont.setText("Change font"); buttonFont.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { FontDialog fontDialog = new FontDialog(shell); if (font != null) fontDialog.setFontList(font.getFontData()); FontData fontData = fontDialog.open(); if (fontData != null) { if (font != null) font.dispose(); font = new Font(display, fontData); label.setFont(font); } else { System.out.println("Setting font action canceled."); } } }); label.setBounds(0, 0, 300, 120); buttonColor.setBounds(50, 130, 90, 25); buttonFont.setBounds(160, 130, 90, 25); shell.setSize(300, 190); 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 filterButton = new Button(composite, SWT.CHECK); filterButton.setText("&Show only healthy"); final ListViewer lv = new ListViewer(composite); lv.setContentProvider(new ItemContentProvider()); lv.setLabelProvider(new ItemLabelProvider()); lv.setInput(new ItemList()); filterButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (((Button) event.widget).getSelection()) lv.addFilter(filter);/*from www . j a v a2 s. c o m*/ else lv.removeFilter(filter); } }); parent.pack(); return composite; }
From source file:ControlEditorTestTwo.java
/** * Creates the main window's contents/*from w ww.j av a 2 s .c om*/ * * @param shell the main window */ private void createContents(final Shell shell) { color = new Color(shell.getDisplay(), 255, 0, 0); // Create a composite that will be the parent of the editor final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color); composite.setBounds(0, 0, 300, 100); // Create the editor ControlEditor editor = new ControlEditor(composite); // Create the control associated with the editor Button button = new Button(composite, SWT.PUSH); button.setText("Change Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ColorDialog dialog = new ColorDialog(shell); if (color != null) dialog.setRGB(color.getRGB()); RGB rgb = dialog.open(); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor along the bottom of the parent composite editor.grabHorizontal = true; editor.verticalAlignment = SWT.BOTTOM; Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumHeight = size.y; editor.setEditor(button); }
From source file:ChooseColor.java
/** * Creates the window contents//from ww w.j a va 2 s . c o m * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, false)); // Start with Celtics green color = new Color(shell.getDisplay(), new RGB(0, 255, 0)); // Use a label full of spaces to show the color final Label colorLabel = new Label(shell, SWT.NONE); colorLabel.setText(" "); colorLabel.setBackground(color); Button button = new Button(shell, SWT.PUSH); button.setText("Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(shell); // Set the selected color in the dialog from // user's selected color dlg.setRGB(colorLabel.getBackground().getRGB()); // Change the title bar text dlg.setText("Choose a Color"); // Open the dialog and retrieve the selected color RGB rgb = dlg.open(); if (rgb != null) { // Dispose the old color, create the // new one, and set into the label color.dispose(); color = new Color(shell.getDisplay(), rgb); colorLabel.setBackground(color); } } }); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button preserveCase = new Button(composite, SWT.CHECK); preserveCase.setText("&Preserve case"); final TreeViewer tv = new TreeViewer(composite); tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tv.setContentProvider(new FileTreeContentProvider()); tv.setLabelProvider(new FileTreeLabelProvider()); tv.setInput("root"); preserveCase.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean preserveCase = ((Button) event.widget).getSelection(); FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider(); ftlp.setPreserveCase(preserveCase); }/*from w ww . ja v a 2s .c o m*/ }); return composite; }