CoolBar是一个容器,里面可以放置多个工具栏,CoolItem代表一个工具栏,基于CoolBar做出的工具栏,可以拖动,改变排放的位置。 final ViewForm vf=new ViewForm(shell, SWT.NONE);
vf.setLayout(new FillLayout());
final Text text=new Text(vf, SWT.BORDER|SWT.V_SCROLL);
vf.setContent(text);
CoolBar cb=new CoolBar(vf, SWT.NONE);
ToolBar tb=new ToolBar(cb, SWT.NONE);
ToolItem ti=new ToolItem(tb, SWT.PUSH);
ti.setText("取得");
ti.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
MessageDialog.openInformation(null, null, text.getText());
}
});
ToolBar tb2=new ToolBar(cb, SWT.NONE);
ToolItem ti2=new ToolItem(tb2, SWT.PUSH);
ti2.setText("删除");
ti2.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent arg0) {
text.setText("");
}
});
CoolItem ci=new CoolItem(cb, SWT.NONE);
ci.setControl(tb);
tb.pack();
Point size=tb.getSize();
ci.setSize(size);
ci.setMinimumSize(size);
CoolItem ci2=new CoolItem(cb, SWT.NONE);
ci2.setControl(tb2);
tb2.pack();
Point size2=tb2.getSize();
ci2.setSize(size2);
ci2.setMinimumSize(size2);
vf.setTopLeft(cb);
cb.addControlListener(new ControlAdapter()
{
@Override
public void controlResized(ControlEvent arg0) {
vf.layout();
}
});