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

2025-09-28 06:57:22

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按钮

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢