Example usage for org.eclipse.swt.widgets Button setLayoutData

List of usage examples for org.eclipse.swt.widgets Button setLayoutData

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button setLayoutData.

Prototype

public void setLayoutData(Object layoutData) 

Source Link

Document

Sets the layout data associated with the receiver to the argument.

Usage

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  . jav a2s .co  m
    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:SendMessage.java

/**
 * Creates the main window's contents//from  ww  w.  j  a v a2s  .  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(5, true));

    // Create a big text box for the message text
    final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 5;
    text.setLayoutData(data);

    // Create the Confirm button
    Button confirm = new Button(composite, SWT.PUSH);
    confirm.setText("Confirm");
    confirm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Error button
    Button error = new Button(composite, SWT.PUSH);
    error.setText("Error");
    error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Information button
    Button information = new Button(composite, SWT.PUSH);
    information.setText("Information");
    information.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Question button
    Button question = new Button(composite, SWT.PUSH);
    question.setText("Question");
    question.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Warning button
    Button warning = new Button(composite, SWT.PUSH);
    warning.setText("Warning");
    warning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label to display the return value
    final Label label = new Label(composite, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 5;
    label.setLayoutData(data);

    // Save ourselves some typing
    final Shell shell = parent.getShell();

    // Display a Confirmation dialog
    confirm.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean b = MessageDialog.openConfirm(shell, "Confirm", text.getText());
            label.setText("Returned " + Boolean.toString(b));
        }
    });

    // Display an Error dialog
    error.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            MessageDialog.openError(shell, "Error", text.getText());
            label.setText("Returned void");
        }
    });

    // Display an Information dialog
    information.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            MessageDialog.openInformation(shell, "Information", text.getText());
            label.setText("Returned void");
        }
    });

    // Display a Question dialog
    question.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean b = MessageDialog.openQuestion(shell, "Question", text.getText());
            label.setText("Returned " + Boolean.toString(b));
        }
    });

    // Display a Warning dialog
    warning.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            MessageDialog.openWarning(shell, "Warning", text.getText());
            label.setText("Returned void");
        }
    });

    return composite;
}

From source file:BorderLayout.java

public BorderLayoutSample() {
    shell.setLayout(new BorderLayout());

    Button buttonWest = new Button(shell, SWT.PUSH);
    buttonWest.setText("West");
    buttonWest.setLayoutData(new BorderLayout.BorderData(BorderLayout.WEST));

    Button buttonEast = new Button(shell, SWT.PUSH);
    buttonEast.setText("East");
    buttonEast.setLayoutData(new BorderLayout.BorderData(BorderLayout.EAST));

    Button buttonNorth = new Button(shell, SWT.PUSH);
    buttonNorth.setText("North");
    buttonNorth.setLayoutData(new BorderLayout.BorderData(BorderLayout.NORTH));

    Button buttonSouth = new Button(shell, SWT.PUSH);
    buttonSouth.setText("South");
    buttonSouth.setLayoutData(new BorderLayout.BorderData(BorderLayout.SOUTH));

    Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    text.setText("Center");
    text.setLayoutData(new BorderLayout.BorderData(BorderLayout.CENTER));

    shell.pack();/*from w ww.  j  a v  a  2  s. 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:ShowPrograms.java

/**
 * Creates the main window's contents//  w ww  .j  av  a 2s . c  o m
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new GridLayout(2, false));

    // Create the label and combo for the extensions
    new Label(shell, SWT.NONE).setText("Extension:");
    Combo extensionsCombo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
    extensionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label and the
    new Label(shell, SWT.NONE).setText("Program:");
    final Label programName = new Label(shell, SWT.NONE);
    programName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Fill the combo with the extensions on the system
    String[] extensions = Program.getExtensions();
    for (int i = 0, n = extensions.length; i < n; i++) {
        extensionsCombo.add(extensions[i]);
    }

    // Add a handler to get the selected extension, look up the associated
    // program, and display the program's name
    extensionsCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Combo combo = (Combo) event.widget;

            // Get the program for the extension
            Program program = Program.findProgram(combo.getText());

            // Display the program's name
            programName.setText(program == null ? "(None)" : program.getName());
        }
    });

    // Create a list box to show all the programs on the system
    List allPrograms = new List(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    allPrograms.setLayoutData(data);

    // Put all the known programs into the list box
    Program[] programs = Program.getPrograms();
    for (int i = 0, n = programs.length; i < n; i++) {
        String name = programs[i].getName();
        allPrograms.add(name);
        allPrograms.setData(name, programs[i]);
    }

    // Add a field for a data file
    new Label(shell, SWT.NONE).setText("Data File:");
    final Text dataFile = new Text(shell, SWT.BORDER);
    dataFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Double-clicking a program in the list launches the program
    allPrograms.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent event) {
            List list = (List) event.widget;
            if (list.getSelectionCount() > 0) {
                String programName = list.getSelection()[0];
                Program program = (Program) list.getData(programName);
                program.execute(dataFile.getText());
            }
        }
    });

    // Let them use launch instead of execute
    Button launch = new Button(shell, SWT.PUSH);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    launch.setLayoutData(data);
    launch.setText("Use Program.launch() instead of Program.execute()");
    launch.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Use launch
            Program.launch(dataFile.getText());
        }
    });
}

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);

    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);//from   ww  w.  j  av a2  s.  c om

    //      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:org.jfree.experimental.chart.swt.editor.SWTChartEditor.java

/**
 * Creates a new editor./*w w  w .j  a v a  2  s.c o  m*/
 * 
 * @param shell2 the display.
 * @param chart2edit the chart to edit.
 */
public SWTChartEditor(Shell shell2, JFreeChart chart2edit) {

    this.shell = new Shell(Display.getDefault(), SWT.DIALOG_TRIM);
    this.shell.setSize(400, 500);
    this.chart = chart2edit;
    this.shell.setText(
            ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle").getString("Chart_Properties"));
    GridLayout layout = new GridLayout(2, true);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5;
    this.shell.setLayout(layout);
    Composite main = new Composite(this.shell, SWT.NONE);
    main.setLayout(new FillLayout());
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TabFolder tab = new TabFolder(main, SWT.BORDER);
    // build first tab
    TabItem item1 = new TabItem(tab, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Title") + " ");
    this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle());
    item1.setControl(this.titleEditor);
    // build second tab
    TabItem item2 = new TabItem(tab, SWT.NONE);
    item2.setText(" " + localizationResources.getString("Plot") + " ");
    this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot());
    item2.setControl(this.plotEditor);
    // build the third tab
    TabItem item3 = new TabItem(tab, SWT.NONE);
    item3.setText(" " + localizationResources.getString("Other") + " ");
    this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart);
    item3.setControl(this.otherEditor);

    // ok and cancel buttons
    Button ok = new Button(this.shell, SWT.PUSH | SWT.OK);
    ok.setText(" Ok ");
    ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateChart(SWTChartEditor.this.chart);
            SWTChartEditor.this.shell.dispose();
        }
    });
    Button cancel = new Button(this.shell, SWT.PUSH);
    cancel.setText(" Cancel ");
    cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            SWTChartEditor.this.shell.dispose();
        }
    });
}

From source file:com.rcp.wbw.demo.editor.SWTChartEditor.java

/**
 * Creates a new editor.//from ww  w . ja  va2 s.  com
 * 
 * @param display
 *            the display.
 * @param chart2edit
 *            the chart to edit.
 */
public SWTChartEditor(Display display, JFreeChart chart2edit) {
    this.shell = new Shell(display, SWT.DIALOG_TRIM);
    this.shell.setSize(400, 500);
    this.chart = chart2edit;
    this.shell.setText(ResourceBundleWrapper.getBundle("org.jfree.chart.LocalizationBundle")
            .getString("Chart_Properties"));
    GridLayout layout = new GridLayout(2, true);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5;
    this.shell.setLayout(layout);
    Composite main = new Composite(this.shell, SWT.NONE);
    main.setLayout(new FillLayout());
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TabFolder tab = new TabFolder(main, SWT.BORDER);
    // build first tab
    TabItem item1 = new TabItem(tab, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Title") + " ");
    this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle());
    item1.setControl(this.titleEditor);
    // build second tab
    TabItem item2 = new TabItem(tab, SWT.NONE);
    item2.setText(" " + localizationResources.getString("Plot") + " ");
    this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot());
    item2.setControl(this.plotEditor);
    // build the third tab
    TabItem item3 = new TabItem(tab, SWT.NONE);
    item3.setText(" " + localizationResources.getString("Other") + " ");
    this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart);
    item3.setControl(this.otherEditor);

    // ok and cancel buttons
    Button ok = new Button(this.shell, SWT.PUSH | SWT.OK);
    ok.setText(" Ok ");
    ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateChart(SWTChartEditor.this.chart);
            SWTChartEditor.this.shell.dispose();
        }
    });
    Button cancel = new Button(this.shell, SWT.PUSH);
    cancel.setText(" Cancel ");
    cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            SWTChartEditor.this.shell.dispose();
        }
    });
}

From source file:org.jfree.experimental.chart.swt.editor.SWTOtherEditor.java

/**
 * Creates a new instance.//from ww  w .  j av  a  2s.com
 * 
 * @param parent  the parent.
 * @param style  the style.
 * @param chart  the chart.
 */
public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));

    // row 1: antialiasing
    this.antialias = new Button(general, SWT.CHECK);
    this.antialias.setText(localizationResources.getString("Draw_anti-aliased"));
    this.antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    this.antialias.setSelection(chart.getAntiAlias());

    //row 2: background paint for the chart
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTOtherEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTOtherEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
}

From source file:com.rcp.wbw.demo.editor.SWTOtherEditor.java

/**
 * Creates a new instance./*from w ww  .jav  a 2s .com*/
 * 
 * @param parent
 *            the parent.
 * @param style
 *            the style.
 * @param chart
 *            the chart.
 */
public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));

    // row 1: antialiasing
    this.antialias = new Button(general, SWT.CHECK);
    this.antialias.setText(localizationResources.getString("Draw_anti-aliased"));
    this.antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    this.antialias.setSelection(chart.getAntiAlias());

    // row 2: background paint for the chart
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTOtherEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTOtherEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
}

From source file:EmailForm.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    // Sets up the toolkit.
    FormToolkit toolkit = new FormToolkit(getShell().getDisplay());

    // Creates a form instance.
    // Form form = toolkit.createForm(composite);
    ScrolledForm form = toolkit.createScrolledForm(composite);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Sets title.
    form.setText("Composing an Email Message");

    // Adds body contents.
    form.getBody().setLayout(new GridLayout(2, false));
    Label label = toolkit.createLabel(form.getBody(), "To: ", SWT.NULL);
    Text textTo = toolkit.createText(form.getBody(), "");
    textTo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = toolkit.createLabel(form.getBody(), "Subject: ", SWT.NULL);
    Text textSubject = toolkit.createText(form.getBody(), "");
    textSubject.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = toolkit.createLabel(form.getBody(), "Message: ", SWT.NULL);
    Text textMessage = toolkit.createText(form.getBody(), "");
    textMessage.setLayoutData(new GridData(GridData.FILL_BOTH));

    label = toolkit.createLabel(form.getBody(), "Option: ", SWT.NULL);
    Button buttonOption = toolkit.createButton(form.getBody(), "save a copy", SWT.CHECK);

    Button buttonClose = toolkit.createButton(form.getBody(), "Close", SWT.PUSH);
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;/*from  w ww . j ava2s.  co  m*/
    gridData.horizontalAlignment = GridData.END;
    buttonClose.setLayoutData(gridData);

    // Button button = toolkit.createButton(form.getBody(), "Test", SWT.NULL);   

    // Adds tool bar items.
    form.getToolBarManager().add(new Action("Send") {
        public void run() {
            System.out.println("Sending email ...");
        }
    });

    form.getToolBarManager().add(new Action("Cancel") {
        public void run() {
            System.out.println("Cancelled.");
        }
    });

    form.updateToolBar();

    return composite;
}