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

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

Introduction

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

Prototype

public void addSelectionListener(SelectionListener listener) 

Source Link

Document

Adds the listener to the collection of listeners who will be notified when the control is selected, by sending it one of the messages defined in the SelectionListener interface.

Usage

From source file:MainClass.java

public static void main(String[] a) {

    final Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setSize(250, 200);//w w  w  .jav a  2 s. com

    shell.setLayout(new FormLayout());

    Composite controls = new Composite(shell, SWT.NONE);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    controls.setLayoutData(data);

    final Browser browser = new Browser(shell, SWT.NONE);
    data = new FormData();
    data.top = new FormAttachment(controls);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    controls.setLayout(new GridLayout(6, false));

    Button button = new Button(controls, SWT.PUSH);
    button.setText("Back");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.back();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Forward");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.forward();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Refresh");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.refresh();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Stop");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.stop();
        }
    });

    final Text url = new Text(controls, SWT.BORDER);
    url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    url.setFocus();

    button = new Button(controls, SWT.PUSH);
    button.setText("Go");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.setUrl(url.getText());
        }
    });

    shell.setDefaultButton(button);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet295.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Shell");
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginWidth = 10;//from  w ww .  java 2  s . c  o m
    fillLayout.marginHeight = 10;
    shell.setLayout(fillLayout);

    Button open = new Button(shell, SWT.PUSH);
    open.setText("Prompt for a String");
    open.addSelectionListener(widgetSelectedAdapter(e -> {
        final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        dialog.setText("Dialog Shell");
        FormLayout formLayout = new FormLayout();
        formLayout.marginWidth = 10;
        formLayout.marginHeight = 10;
        formLayout.spacing = 10;
        dialog.setLayout(formLayout);

        Label label = new Label(dialog, SWT.NONE);
        label.setText("Type a String:");
        FormData data = new FormData();
        label.setLayoutData(data);

        Button cancel = new Button(dialog, SWT.PUSH);
        cancel.setText("Cancel");
        data = new FormData();
        data.width = 60;
        data.right = new FormAttachment(100, 0);
        data.bottom = new FormAttachment(100, 0);
        cancel.setLayoutData(data);
        cancel.addSelectionListener(widgetSelectedAdapter(event -> {
            System.out.println("User cancelled dialog");
            dialog.close();
        }));

        final Text text = new Text(dialog, SWT.BORDER);
        data = new FormData();
        data.width = 200;
        data.left = new FormAttachment(label, 0, SWT.DEFAULT);
        data.right = new FormAttachment(100, 0);
        data.top = new FormAttachment(label, 0, SWT.CENTER);
        data.bottom = new FormAttachment(cancel, 0, SWT.DEFAULT);
        text.setLayoutData(data);

        Button ok = new Button(dialog, SWT.PUSH);
        ok.setText("OK");
        data = new FormData();
        data.width = 60;
        data.right = new FormAttachment(cancel, 0, SWT.DEFAULT);
        data.bottom = new FormAttachment(100, 0);
        ok.setLayoutData(data);
        ok.addSelectionListener(widgetSelectedAdapter(event -> {
            System.out.println("User typed: " + text.getText());
            dialog.close();
        }));

        dialog.setDefaultButton(ok);
        dialog.pack();
        dialog.open();
    }));
    shell.pack();
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TreeEditorButton.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Text Tree Editor");
    shell.setLayout(new FillLayout());

    final Tree tree = new Tree(shell, SWT.SINGLE);
    for (int i = 0; i < 3; i++) {
        TreeItem iItem = new TreeItem(tree, SWT.NONE);
        iItem.setText("Item " + (i + 1));
        for (int j = 0; j < 3; j++) {
            TreeItem jItem = new TreeItem(iItem, SWT.NONE);
            jItem.setText("Sub Item " + (j + 1));
            for (int k = 0; k < 3; k++) {
                new TreeItem(jItem, SWT.NONE).setText("Sub Sub Item " + (k + 1));
            }/*w w  w .  j a v  a  2 s  . c o  m*/
            jItem.setExpanded(true);
        }
        iItem.setExpanded(true);
    }

    final TreeEditor editor = new TreeEditor(tree);
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;

    tree.addMouseListener(new MouseAdapter() {
        public void mouseDown(MouseEvent event) {
            final TreeItem item = tree.getSelection()[0];

            final Button bn = new Button(tree, SWT.NONE);
            bn.setText("click");
            bn.setFocus();

            bn.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent arg0) {
                    int style = SWT.ICON_QUESTION | SWT.YES | SWT.NO;

                    MessageBox messageBox = new MessageBox(shell, style);
                    messageBox.setMessage("Message");
                    int rc = messageBox.open();

                    item.setText(rc + "");
                    bn.dispose();
                }

                public void widgetDefaultSelected(SelectionEvent arg0) {
                }
            });

            editor.setEditor(bn, item);
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet4.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 4");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Open Dialog ...");
    b.pack();/*from  ww  w .ja v a 2s.c  om*/
    Rectangle clientArea = shell.getClientArea();
    b.setLocation(clientArea.x + 10, clientArea.y + 10);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
        dialog.addListener(SWT.Traverse, t -> {
            if (t.detail == SWT.TRAVERSE_ESCAPE) {
                t.doit = false;
            }
        });
        dialog.open();
    }));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ButtonClass.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(200, 200);//from  w  w w .ja va  2 s  .  c om
    shell.setText("Button Example");

    final Button button = new Button(shell, SWT.PUSH);
    button.setBounds(40, 50, 50, 20);
    button.setText("Click Me");

    final Text text = new Text(shell, SWT.BORDER);
    text.setBounds(100, 50, 70, 20);

    button.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            text.setText("No problem");
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            text.setText("No worries!");
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.examples.accessibility.AccessibleTableExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    shell.setText("Accessible Table Example");

    Group group = new Group(shell, SWT.NONE);
    group.setText("Tables With Accessible Cell Children");
    group.setLayout(new GridLayout());

    new Label(group, SWT.NONE).setText("CTable with column headers");

    table1 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    table1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    table1.setHeaderVisible(true);/*www. j a v  a  2  s  . c o  m*/
    table1.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        CTableColumn column = new CTableColumn(table1, SWT.NONE);
        column.setText("Col " + col);
        column.setWidth(50);
    }
    for (int row = 0; row < 4; row++) {
        CTableItem item = new CTableItem(table1, SWT.NONE);
        item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row });
    }

    Composite btnGroup = new Composite(group, SWT.NONE);
    btnGroup.setLayout(new FillLayout(SWT.VERTICAL));
    Button btn = new Button(btnGroup, SWT.PUSH);
    btn.setText("Add rows");
    btn.addSelectionListener(widgetSelectedAdapter(e -> {
        int currSize = table1.getItemCount();
        int colCount = table1.getColumnCount();
        CTableItem item = new CTableItem(table1, SWT.NONE);
        String[] cells = new String[colCount];

        for (int i = 0; i < colCount; i++) {
            cells[i] = "C" + i + "R" + currSize;
        }
        item.setText(cells);
    }));
    btn = new Button(btnGroup, SWT.PUSH);
    btn.setText("Remove rows");
    btn.addSelectionListener(widgetSelectedAdapter(e -> {
        int currSize = table1.getItemCount();
        if (currSize > 0) {
            table1.remove(currSize - 1);
        }
    }));
    btn = new Button(btnGroup, SWT.PUSH);
    btn.setText("Remove selected rows");
    btn.addSelectionListener(widgetSelectedAdapter(e -> {
        CTableItem[] selectedItems = table1.getSelection();
        for (CTableItem selectedItem : selectedItems) {
            selectedItem.dispose();
        }
    }));
    btn = new Button(btnGroup, SWT.PUSH);
    btn.setText("Add column");
    btn.addSelectionListener(widgetSelectedAdapter(e -> {
        int currSize = table1.getColumnCount();
        CTableColumn item = new CTableColumn(table1, SWT.NONE);
        item.setText("Col " + currSize);
        item.setWidth(50);
    }));
    btn = new Button(btnGroup, SWT.PUSH);
    btn.setText("Remove last column");

    btn.addSelectionListener(widgetSelectedAdapter(e -> {
        int colCount = table1.getColumnCount();
        if (colCount > 0) {
            CTableColumn column = table1.getColumn(colCount - 1);
            column.dispose();
        }
    }));

    new Label(group, SWT.NONE).setText("CTable used as a list");

    CTable table2 = new CTable(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    table2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    table2.setLinesVisible(true);
    for (String element : itemText) {
        CTableItem item = new CTableItem(table2, SWT.NONE);
        item.setText(element);
    }

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet361.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 361");
    shell.setText("Translate and Rotate an AWT Image in an SWT GUI");
    shell.setLayout(new GridLayout(8, false));

    Button fileButton = new Button(shell, SWT.PUSH);
    fileButton.setText("&Open Image File");
    fileButton.addSelectionListener(widgetSelectedAdapter(e -> {
        String filename = new FileDialog(shell).open();
        if (filename != null) {
            image = Toolkit.getDefaultToolkit().getImage(filename);
            canvas.repaint();/*from   ww  w . j  a v a  2  s  .com*/
        }
    }));

    new Label(shell, SWT.NONE).setText("Translate &X by:");
    final Combo translateXCombo = new Combo(shell, SWT.NONE);
    translateXCombo.setItems("0", "image width", "image height", "100", "200");
    translateXCombo.select(0);
    translateXCombo.addModifyListener(e -> {
        translateX = numericValue(translateXCombo);
        canvas.repaint();
    });

    new Label(shell, SWT.NONE).setText("Translate &Y by:");
    final Combo translateYCombo = new Combo(shell, SWT.NONE);
    translateYCombo.setItems("0", "image width", "image height", "100", "200");
    translateYCombo.select(0);
    translateYCombo.addModifyListener(e -> {
        translateY = numericValue(translateYCombo);
        canvas.repaint();
    });

    new Label(shell, SWT.NONE).setText("&Rotate by:");
    final Combo rotateCombo = new Combo(shell, SWT.NONE);
    rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8");
    rotateCombo.select(0);
    rotateCombo.addModifyListener(e -> {
        rotate = numericValue(rotateCombo);
        canvas.repaint();
    });

    Button printButton = new Button(shell, SWT.PUSH);
    printButton.setText("&Print Image");
    printButton.addSelectionListener(widgetSelectedAdapter(e -> {
        performPrintAction(display, shell);
    }));

    composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1);
    data.widthHint = 640;
    data.heightHint = 480;
    composite.setLayoutData(data);
    Frame frame = SWT_AWT.new_Frame(composite);
    canvas = new Canvas() {
        @Override
        public void paint(Graphics g) {
            if (image != null) {
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());

                /* Use Java2D here to modify the image as desired. */
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform t = new AffineTransform();
                t.translate(translateX, translateY);
                t.rotate(rotate);
                g2d.setTransform(t);
                /*------------*/

                g.drawImage(image, 0, 0, this);
            }
        }
    };
    frame.add(canvas);
    composite.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            e.result = "Image drawn in AWT Canvas";
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ViewFormCreate.java

public static void main(String[] args) {

    Shell shell = new Shell(display);
    shell.setText("Look");

    shell.setLayout(new GridLayout(1, false));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("New Document");

    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new FillLayout());

    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            createViewFormHelper(composite, "Document " + (++count));
            composite.layout();/*w  w  w .j a v a 2  s  .c o m*/
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:KalendarDialog.java

/**
 * @param args//from   ww  w.  j a  v a  2s  .  co  m
 */
public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("");

    FillLayout fl = new FillLayout();
    shell.setLayout(fl);
    Button open = new Button(shell, SWT.PUSH);
    open.setText("open");
    open.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            KalendarDialog cd = new KalendarDialog(shell);
            System.out.println(cd.open());
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}

From source file:org.eclipse.swt.snippets.Snippet373.java

@SuppressWarnings("restriction")
public static void main(String[] args) {
    System.setProperty("swt.autoScale", "quarter");
    Display display = new Display();
    final Image eclipse = new Image(display, filenameProvider);
    final Image eclipseToolBar1 = new Image(display, filenameProvider);
    final Image eclipseToolBar2 = new Image(display, filenameProvider);
    final Image eclipseTableHeader = new Image(display, filenameProvider);
    final Image eclipseTableItem = new Image(display, filenameProvider);
    final Image eclipseTree1 = new Image(display, filenameProvider);
    final Image eclipseTree2 = new Image(display, filenameProvider);
    final Image eclipseCTab1 = new Image(display, filenameProvider);
    final Image eclipseCTab2 = new Image(display, filenameProvider);

    Shell shell = new Shell(display);
    shell.setText("Snippet 373");
    shell.setImage(eclipse);/*from   w  w w .  j av a  2s  .  com*/
    shell.setText("DynamicDPI @ " + DPIUtil.getDeviceZoom());
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    shell.setLocation(100, 100);
    shell.setSize(500, 600);
    shell.addListener(SWT.ZoomChanged, new Listener() {
        @Override
        public void handleEvent(Event e) {
            if (display.getPrimaryMonitor().equals(shell.getMonitor())) {
                MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL);
                box.setText(shell.getText());
                box.setMessage("DPI changed, do you want to exit & restart ?");
                e.doit = (box.open() == SWT.OK);
                if (e.doit) {
                    shell.close();
                    System.out.println("Program exit.");
                }
            }
        }
    });

    // Menu
    Menu bar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(bar);
    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText("&File");
    fileItem.setImage(eclipse);
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    MenuItem subItem = new MenuItem(submenu, SWT.PUSH);
    subItem.addListener(SWT.Selection, e -> System.out.println("Select All"));
    subItem.setText("Select &All\tCtrl+A");
    subItem.setAccelerator(SWT.MOD1 + 'A');
    subItem.setImage(eclipse);

    // CTabFolder
    CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CTabItem cTabItem = new CTabItem(folder, i % 2 == 0 ? SWT.CLOSE : SWT.NONE);
        cTabItem.setText("Item " + i);
        Text textMsg = new Text(folder, SWT.MULTI);
        textMsg.setText("Content for Item " + i);
        cTabItem.setControl(textMsg);
        cTabItem.setImage((i % 2 == 1) ? eclipseCTab1 : eclipseCTab2);
    }

    // PerMonitorV2 setting
    //      Label label = new Label (shell, SWT.BORDER);
    //      label.setText("PerMonitorV2 value before:after:Error");
    //      Text text = new Text(shell, SWT.BORDER);
    //      text.setText(DPIUtil.BEFORE + ":" + DPIUtil.AFTER + ":" + DPIUtil.RESULT);

    // Composite for Label, Button, Tool-bar
    Composite composite = new Composite(shell, SWT.BORDER);
    composite.setLayout(new RowLayout(SWT.HORIZONTAL));

    // Label with Image
    Label label1 = new Label(composite, SWT.BORDER);
    label1.setImage(eclipse);

    // Label with text only
    Label label2 = new Label(composite, SWT.BORDER);
    label2.setText("No Image");

    // Button with text + Old Image Constructor
    Button oldButton1 = new Button(composite, SWT.PUSH);
    oldButton1.setText("Old Img");
    oldButton1.setImage(new Image(display, IMAGE_PATH_100));

    // Button with Old Image Constructor
    //      Button oldButton2 = new Button(composite, SWT.PUSH);
    //      oldButton2.setImage(new Image(display, filenameProvider.getImagePath(100)));

    // Button with Image
    Button createDialog = new Button(composite, SWT.PUSH);
    createDialog.setText("Child Dialog");
    createDialog.setImage(eclipse);
    createDialog.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE);
            dialog.setText("Child Dialog");
            RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
            dialog.setLayout(rowLayout);
            Label label = new Label(dialog, SWT.BORDER);
            label.setImage(eclipse);
            Point location = shell.getLocation();
            dialog.setLocation(location.x + 250, location.y + 50);
            dialog.pack();
            dialog.open();
        }
    });

    // Toolbar with Image
    ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.BORDER);
    Rectangle clientArea = shell.getClientArea();
    toolBar.setLocation(clientArea.x, clientArea.y);
    for (int i = 0; i < 2; i++) {
        int style = i % 2 == 1 ? SWT.DROP_DOWN : SWT.PUSH;
        ToolItem toolItem = new ToolItem(toolBar, style);
        toolItem.setImage((i % 2 == 0) ? eclipseToolBar1 : eclipseToolBar2);
        toolItem.setEnabled(i % 2 == 0);
    }
    toolBar.pack();

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Refresh-Current Monitor : Zoom");
    Text text1 = new Text(shell, SWT.BORDER);
    Monitor monitor = button.getMonitor();
    text1.setText("" + monitor.getZoom());
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            Monitor monitor = button.getMonitor();
            text1.setText("" + monitor.getZoom());
        }
    });
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Refresh-Both Monitors : Zoom");
    Text text2 = new Text(shell, SWT.BORDER);
    Monitor[] monitors = display.getMonitors();
    StringBuilder text2String = new StringBuilder();
    for (int i = 0; i < monitors.length; i++) {
        text2String.append(monitors[i].getZoom() + (i < (monitors.length - 1) ? " - " : ""));
    }
    text2.setText(text2String.toString());
    button2.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            Monitor[] monitors = display.getMonitors();
            StringBuilder text2String = new StringBuilder();
            for (int i = 0; i < monitors.length; i++) {
                text2String.append(monitors[i].getZoom() + (i < (monitors.length - 1) ? " - " : ""));
            }
            text2.setText(text2String.toString());
        }
    });

    // Table
    Table table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String titles[] = { "Title 1" };
    for (int i = 0; i < titles.length; i++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText(titles[i]);
        column.setImage(eclipseTableHeader);
    }
    for (int i = 0; i < 1; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, "Data " + i);
        item.setImage(0, eclipseTableItem);
    }
    for (int i = 0; i < titles.length; i++) {
        table.getColumn(i).pack();
    }

    // Tree
    final Tree tree = new Tree(shell, SWT.BORDER);
    for (int i = 0; i < 1; i++) {
        TreeItem iItem = new TreeItem(tree, 0);
        iItem.setText("TreeItem (0) -" + i);
        iItem.setImage(eclipseTree1);
        TreeItem jItem = null;
        for (int j = 0; j < 1; j++) {
            jItem = new TreeItem(iItem, 0);
            jItem.setText("TreeItem (1) -" + j);
            jItem.setImage(eclipseTree2);
            jItem.setExpanded(true);
        }
        tree.select(jItem);
    }

    // Shell Location
    Monitor primary = display.getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    shell.setLocation(x, y);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}