Java SWT 清除表头

我正在开发 SWT GUI,我正在尝试创建一个按钮,按下该按钮即可清除所有表数据和标题。

table.removeAll();

这个命令不能很好地工作,因为它只删除里面的数据,我也需要删除表头。

有解决办法吗?

编辑:在清除标题的代码工作后,如果我尝试添加带有数据的新文件,标题将转到下一点。为什么如果它是空白的?(包含标题名称的 ArrayLists 也被清除)。

第一张图片是上传第一个文件时,点击“开始”按钮后,表格中显示的数据:

http://img4.mukewang.com/611e30d50001b2a810800048.jpg

第二张图片是在表格通过按下另一个按钮清除所有数据之后:

http://img4.mukewang.com/611e30e500012a1008860066.jpg

第三张图片是上传新文件并按“开始”按钮后:

http://img3.mukewang.com/611e30f40001468907320048.jpg

编辑:标题集


            tableConfigurationSystemColumnTools.add("Parameter Name");

            for (String str : tableSystemColumn) {

                String[] a = str.split("PCM");

                tableConfigurationSystemColumnTools.add(a[0].trim());

            }

                for (int loopIndexSystemColumnTools = 0; 

                loopIndexSystemColumnTools < tableConfigurationSystemColumnTools.size(); loopIndexSystemColumnTools++) {

                TableColumn column = new TableColumn(tableConfigurationSystem, SWT.NULL);

                column.setWidth(100);

                column.setText(tableConfigurationSystemColumnTools.get(loopIndexSystemColumnTools));

              }

              for (int loopIndexSystemColumnTools = 0; loopIndexSystemColumnTools < tableConfigurationSystemColumnTools.size(); loopIndexSystemColumnTools++) {

                  tableConfigurationSystem.getColumn(loopIndexSystemColumnTools).pack();

              }

编辑:我已经找到了答案,看看我的评论。


一只斗牛犬
浏览 208回答 2
2回答

largeQ

button.addSelectionListener(new SelectionAdapter() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void widgetSelected(SelectionEvent e) {&nbsp; &nbsp; &nbsp; &nbsp; table.removeAll();&nbsp; &nbsp; &nbsp; &nbsp; TableColumn[] columns = table.getColumns();&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < columns.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; columns[i].setText("");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }});

芜湖不芜

我找到了答案 - 在创建 TableColumn 的“for”循环中,我添加了“index”:TableColumn&nbsp;column&nbsp;=&nbsp;new&nbsp;TableColumn(tableConfigurationSystem,&nbsp;SWT.NONE,&nbsp;loopIndexSystemColumnTools);这是工作。感谢大伙们。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java