CoolBarCombo.java Source code

Java tutorial

Introduction

Here is the source code for CoolBarCombo.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CoolBarCombo {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        CoolBar coolBar = new CoolBar(shell, SWT.BORDER);
        coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        final CoolItem item = new CoolItem(coolBar, SWT.DROP_DOWN);

        Composite c = new Composite(coolBar, SWT.NONE);
        c.setLayout(new FillLayout());
        Combo combo = new Combo(c, SWT.DROP_DOWN);
        combo.add("Option One");
        combo.add("Option Two");
        combo.add("Option Three");

        item.setControl(c);

        Control control = item.getControl();
        Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        pt = item.computeSize(pt.x, pt.y);
        item.setSize(pt);

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

}