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

时间:2024-10-17 09:42:53

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

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

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

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

3、创建TableItem,设置TableEditor,把Button控件加入。TableE蟠校盯昂ditor 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按钮
© 手抄报圈