Java SWT清除表头

问题描述 投票:0回答:2

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

table.removeAll();

此命令不能正常工作,因为它只删除内部数据,我也需要删除表头。

有解决方案吗?

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

第一个图像是第一个文件上传后,点击“开始”按钮后显示在表格上的数据:enter image description here

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

第三张图片是在上传新文件后按“开始”按钮:enter image description here

编辑:标题集

            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();
              }

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

java user-interface swt
2个回答
2
投票
button.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
        table.removeAll();
        TableColumn[] columns = table.getColumns();
        for (int i = 0; i < columns.length; i++) {
            columns[i].setText("");
        }
    }
});

0
投票

我创建了答案 - 在创建TableColumn的“for”循环中,我添加了“index”:

TableColumn column = new TableColumn(tableConfigurationSystem, SWT.NONE, loopIndexSystemColumnTools);

这是有效的。

感谢你们。

© www.soinside.com 2019 - 2024. All rights reserved.