import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
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;
/**
* @author Administrator
* http://www.tutorials.de
*/
public class CoolbarTest extends ApplicationWindow {
public CoolbarTest() {
super(null);
setBlockOnOpen(true);
}
public Control createContents(Composite parent) {
Shell shell = parent.getShell();
shell.setText("CoolbarTest");
CoolBar bar = new CoolBar(shell, SWT.BORDER);
for (int i = 0; i < 2; i++) {
CoolItem item = new CoolItem(bar, SWT.NONE);
Image img = new Image(shell.getDisplay(), "d:/icon" + i + ".gif");
Button button = new Button(bar, SWT.PUSH);
button.setImage(img);
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
item.setPreferredSize(item.computeSize(size.x, size.y));
item.setControl(button);
}
bar.pack();
return shell;
}
public static void main(String[] args) {
CoolbarTest test = new CoolbarTest();
test.open();
Display.getCurrent().dispose();
}
}