The Goal
Keep walking……
posts - 23,  comments - 1,  trackbacks - 0

是JFace的类,继承自ContributionManager,凡是继承了IAction或IContribution接口的对象都可被加至ToolBarManager.你只要花时间为ToolBarManager添加Action,Toolbar和ToolItem实例会自动产生。

你可通过调用ApplicationWindow的createToolBarManager()来为你的应用程序添加一个toolbar。与MenuManager不同的是,createToolBarManager()需要一个style参数,这个参数用来设定ToolBar所用的按钮的风格:flat或normal。

  • ControlContribution

除了MenuManager所用的ContributionItems之外,还有一个新的ContributionItem,只能被ToolBarManager使用——ControlContribution。这个类可将任何能被用于toolbar的Control打包进去。

要使用ControlContribution类,必须要实现抽象方法createControl().

toolBarManager.add(new ControlContribution("Custom") {
protected Control createControl(Composite parent) {
SashForm sf = new SashForm(parent, SWT.NONE);
Button b1 = new Button(sf, SWT.PUSH);
b1.setText("Hello");
Button b2 = new Button(sf, SWT.PUSH);
b2.setText("World");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Selected:" + e);
}
});
return sf;
}
});

如果你希望有任何的事件发生,必须在你的controls上实现SelectionListeners

  • Creating toolbars by hand

如果你不想ToolBarManager来创建toolbar的话,可以手动创建,需要用到ToolBar和ToolItem类.

Toolbar
是一个composite control,包含多个ToolItems.Toolbar由多个小图标按钮组成,一般是16-by-16bitmap图片。每个按钮都对应一个ToolItem。Toolbar可以是水平的也可以是垂直的,默认为水平

ToolItem
每一个ToolItem都有一个图片,如果没有,默认为红色方块。When the user selects a ToolItem from the menu, it broadcasts the event to any registered SelectionListeners.Your application should register a listener with each ToolItem and use that listener to perform whatever logic corresponds to the menu item.

posted on 2006-04-07 16:32 JOO 阅读(658) 评论(0)  编辑  收藏 所属分类: SWT & JFace IN ACTION

只有注册用户登录后才能发表评论。


网站导航:
 
Hit the target!

<2006年4月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用链接

留言簿(2)

随笔分类(23)

随笔档案(22)

文章档案(1)

相册

Neighbor

搜索

  •  

最新评论

阅读排行榜

评论排行榜