Add ToolBar to CoolBar : CoolBar « SWT « Java Tutorial






Add ToolBar to CoolBar
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
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;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class CoolBarToolBar {

  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);
    item.setControl(createToolBar(coolBar));


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

  private static Control createToolBar(Composite composite) {
    ToolBar toolBar = new ToolBar(composite, SWT.NONE);
    ToolItem item = new ToolItem(toolBar, SWT.PUSH);
    item.setText("circle");
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setText("square");
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setText("star");
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setText("triangle");
    return toolBar;
  }
}








17.66.CoolBar
17.66.1.Creating Coolbars
17.66.2.Add ToolBar to CoolBarAdd ToolBar to CoolBar
17.66.3.Add Button and Combo to a CoolBarAdd Button and Combo to a CoolBar
17.66.4.Create a coolbar (relayout when resized)Create a coolbar (relayout when resized)
17.66.5.CoolBar: drop-down a chevron menu containing hidden tool itemsCoolBar: drop-down a chevron menu containing hidden tool items