如何摆脱SWT表中的额外列

时间:2018-01-30 15:20:07

标签: swt

Here is how it appears,As you see there is a small column without any header is being created.我有一个SWT表有三列。现在问题是在创建表并用值填充表后我看到一些额外的列和额外的行。任何人都告诉我怎么能摆脱其中.Below是它的片段。

String[] variables = variableString.split(NodeItemDetailsProvider.INPUT_VARIABLE + DELIMITER);
        String referenceVariables = variables.length > 1 ? variables[1] : ""; //$NON-NLS-1$
        boolean isInputAbsent = referenceVariables.equalsIgnoreCase(StringUtils.EMPTY);
        String refVarsArray[] = referenceVariables.split(NodeItemDetailsProvider.REFERENCE_VARIABLE_SEPARATOR);
        GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, false);
        int tableStyle = SWT.BORDER | SWT.H_SCROLL;
        if (refVarsArray.length > 10) {
            tableStyle = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL;
            gd_table.heightHint = 150;
            gd_table.widthHint = 450;
        }
        Table refVarTable = new Table(top, tableStyle);
        refVarTable.setLayoutData(gd_table);
        refVarTable.setHeaderVisible(false);
        refVarTable.setLinesVisible(true);
        refVarTable.setBackground(TouchstoneStyleSheet.get(ColorKey.HIGHLIGHTED_TEXT_YELLOW_BACKGROUND));
        String[] titles = { "Variable Name", "Variable Value Provided To Reference", //$NON-NLS-1$ //$NON-NLS-2$
                "Variable Value Retrieved From Reference" }; //$NON-NLS-1$
        TableItem header = new TableItem(refVarTable, SWT.NONE);
        header.setBackground(TouchstoneStyleSheet.get(ColorKey.HIGHLIGHTED_TEXT_YELLOW_BACKGROUND));
        final Font font = new Font(null, StringUtils.EMPTY, 9, SWT.BOLD);
        for (int i = 0; i < titles.length; i++) {
            new TableColumn(refVarTable, SWT.NONE);
            header.setFont(i, font);
            header.setText(i, titles[i]);
        }
        for (String row : refVarsArray) {
            String values[] = row.split(NodeItemDetailsProvider.REFERENCE_INPUT_SEPARATOR);
            TableItem item = new TableItem(refVarTable, SWT.NULL | SWT.FULL_SELECTION);
            for (int index = 0; index < values.length; index++) {
                if (values[index].length() > 90) {
                    gd_table.widthHint = 950;
                }
                item.setText(index, values[index]);
            }
        }
        for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
            refVarTable.getColumn(loopIndex).pack();
        }
        refVarTable.addListener(SWT.Dispose, new Listener() {
            @Override
            public void handleEvent(Event event) {
                font.dispose();
            }
    });

0 个答案:

没有答案