Showing Images and Text in Toolbar

Showing both images and text for certain toolbar items is a common requirement. The text is generally placed either to the right or below the image for the action, as shown in Figure 17-3. This improves usability for new users who do not know the meanings of the images. The Workbench supports mixing images and text, but only with programmatic actions.

Let's walk through how this is done. When an application contributes actions to the top-level toolbar, it adds them to an ICoolBarManager. The ICoolBarManager interface extends IContributionManager and can manage both IActions and IContributionItems. Contributed items wrap the SWT controls that are shown in the contribution manager and are ultimately responsible for rendering the items in a menu, a composite, or a coolbar.

 

JFace provides a helper class called ActionContributionItem for directly adding actions to a contribution manager. Contributed action items effectively transfer the properties of an action down to an SWT control. As such, they can be used to configure whether or not text is shown on the toolbar.

To control the ActionContributionItem for an action, first create the toolbar with a style flag that includes SWT.BOTTOM or SWT.RIGHT to indicate where to show the text. Then, for each action, create an ActionConfigurationItem and set its mode to ActionContributionItem.MODE_FORCE_TEXT. Next, call ToolBarManager.add(IContributionItem) to add the contribution item to the toolbar. The following code shows how to do this in Hyperbola's ActionBarAdvisor:

 

org.eclipsercp.hyperbola/ApplicationActionBarAdvisor

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值