SWT学习:[2]Table中添加Button按钮

 时间:2026-02-13 21:47:10

1、以在Table中添加buton控件为例。

SWT学习:[2]Table中添加Button按钮

2、先创建Table,然后添加列TableColumn。代码如下图所示。可根据自己实际情况进行更改。

SWT学习:[2]Table中添加Button按钮

3、创建TableItem,设置TableEditor,把Button控件加入。

TableEditor editor = new TableEditor();

editor.grabHorizontal = true;//自动填充表格

editor.minimumHeight = buttons.getSize().y;//设置editor最小高度

editor.minimumWidth = buttons.getSize().x;//最小宽度

editor.setEditor(buttons, item, columnIndex);//指定给哪个单元格设置该控件。

SWT学习:[2]Table中添加Button按钮

4、上面只是在一个单元格中添加了一个Button控件,我们还可以在单元格中添加2个或者3个控制,需要设置一下它们显示的位置以及控件宽度。

不要自动填充表格,直接设置它们显示的位置。

//editor.grabHorizontal = true;//

editor1.horizontalAlignment = SWT.LEFT;//设置显示在左边

editor2.horizontalAlignment = SWT.RIGHT;显示左右边

editor1.minimumWidth = 30;设置显示宽度

editor2.minimumWidth = 30;

SWT学习:[2]Table中添加Button按钮

SWT学习:[2]Table中添加Button按钮

5、为Table中的button控件添加事件。

SWT学习:[2]Table中添加Button按钮

6、当删除Table中的某一个控件时,需要将控件和Editor都删除。

button.dispose();

editor.dispose();

然后Table再删除该行记录。

SWT学习:[2]Table中添加Button按钮

  • C#如何进行数字类型的算术运算
  • 怎样在Typora中插入代码和代码块
  • 【校园指南】东莞理工学院城市学院奖学金攻略
  • WPS利用VARP函数计算方差
  • 在C++中如何来实现进制转换
  • 热门搜索
    怎么改照片格式 根号怎么打出来 方案怎么写范文 中间的点怎么打 现实表现怎么写 贫困生申请书怎么写 奔驰车钥匙怎么换电池 干发帽怎么用 宝宝缺钙怎么补 澳门城市大学怎么样