SWT-ToolBar和CoolBar

ToolBar与ToolItem

ToolBar是用来放置工具按钮ToolItem的容器。ToolItem能同时显示设置图像和文字。ToolItem有多种风格样式:

  • ToolItem:普通风格的工具条按钮;
  • Check ToolItem:复选框样式的工具条按钮;
  • Radio ToolItem:单选框样式的工具条按钮,同样具有排他性。
  • DropDown ToolItem:下拉样式的工具条按钮,配合Menu控件使用。
  • Separator ToolItem:分隔条效果的工具条按钮。

创建工具条和按钮

在这里插入图片描述

源码

ToolBarComposite

继承Composite类,包含各样式的工具条按钮。

package mailrcp.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class ToolBarComposite extends Composite {
   
    
    /**
     * 构造函数
     * 
     * @param parent 父面板
     * @param style 样式
     */
    public ToolBarComposite(Composite parent, int style) {
   
        super(parent, style);
        setLayout(new GridLayout(1, false));
        
        final ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.WRAP | SWT.RIGHT);
        toolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        
        // ### 普通风格的工具条按钮 ###
        ToolItem toolItem1 = new ToolItem(toolBar, SWT.NONE);
        toolItem1.setText("ToolItem1");
        ToolItem toolItem2 = new ToolItem(toolBar, SWT.NONE);
        toolItem2.setText("ToolItem2");
        new ToolItem(toolBar, SWT.SEPARATOR);
        
        // ### 复选框样式的工具条按钮 ###
        ToolItem checkToolItem1 = new ToolItem(toolBar, SWT.CHECK);
        checkToolItem1.setText("Check Item1");
        ToolItem checkToolItem2 = new ToolItem(toolBar, SWT.CHECK);
        checkToolItem2.setText("Check Item2");
        new ToolItem(toolBar, SWT.SEPARATOR);
        
        // ### 单选框样式的工具条按钮 ###
        ToolItem radioToolItem1 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值