每次扩展部分时,表查看器宽度都会增加

时间:2015-07-24 07:32:04

标签: swt eclipse-rcp jface

我创建了一个Table,它位于表单Section中。每次扩展表大小(Width)都会增长。我正在使用TableColoumnLayout作为表查看器组合。

我检查了这个错误https://bugs.eclipse.org/bugs/show_bug.cgi?id=215997。我没有运气。

有什么建议吗?

 objectiveSection = toolkit.createSection(composite,        Section.DESCRIPTION|Section.TITLE_BAR|
              Section.TWISTIE|Section.EXPANDED);
       objectiveSection.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground());
    objectiveSection.setToggleColor(toolkit.getColors().getColor(FormColors.SEPARATOR));


    GridData data=new GridData(GridData.FILL, GridData.FILL, true, true);
    objectiveSection.setLayoutData(data);
    toolkit.createCompositeSeparator(objectiveSection); 
    toolkit.adapt(objectiveSection);

    /**
     * Creating a client inside the section
     */
    Composite objective = toolkit.createComposite(objectiveSection, SWT.BORDER);


    /**
     * creating the object table model and object table.
     */
    TableModel objectiveModel=new ObjectiveTableModel();

    GridData gds = new GridData(GridData.FILL,GridData.FILL,true,true);

    objectiveTable=new  CustomTable(objectiveModel, objective, true, true, gds);
    /**
     * column for object viewer     
     */
    objectiveTable.createTableViewerColumn("List of Behaviors", 0);
    objectiveTable.enableCellEdit();
    objectiveTable.autoFocus();
    toolkit.adapt(objective);

    objectiveSection.setText("Behaviours");
    objectiveSection.setDescription("The section contains the Behaviours of the selected operation"); //$NON-NLS-1$
    objectiveSection.setClient(objective);
    objectiveSection.setExpanded(true);
    objectiveSection.setEnabled(true);
    objectiveSection.addExpansionListener(new ExpansionAdapter() {
        public void expansionStateChanged(ExpansionEvent e) {
            form.reflow(false);
        }
    });

我的表格会动态获取值。每次我调整列的大小

     this.table.setRedraw(false);   
     for (int i = 0, n = this.table.getColumnCount(); i < n; i++){
       this.table.getColumn(i).pack();
       int minWidth=this.table.getColumn(i).getWidth();
       this.layout.setColumnData(this.table.getColumn(i), new ColumnWeightData(25,minWidth));
    }

    this.table.setRedraw(true );
    this.composite.layout();

1 个答案:

答案 0 :(得分:0)

似乎因为以下行而发生:

GridData gds = new GridData(GridData.FILL,GridData.FILL,true,true);

您要求表格填充其容器并占用多余空间。 请尝试改为:

GridData gds = new GridData(GridData.CENTER,GridData.CENTER,false,false);