Problem with Table columns width

Hi,

I have two components: Tree and Table.
I am using Tree to control content of Table. So I have added ValueChangeListener to Tree that orders Table to load particular content.
Table, while loading content creates columns end sets theirs width. And my problems is, that this width is ignored, at first.
So when I click on Tree, table changes its content but columns width is nothing like I would like to be. Columns are fitted to whole table width. Lets say my table is 400px, and I setted up column 1 (30px), and column 2 (50px). After clicking on tree, those columns fill all table width on undefined ratio.
But this is not over. When I click again on the same item on Tree, nothings happens, but when I click third time, columns are resized to desired sizes… have you got any idea how to correct this? Please help…

Regards,
Darek

From your description it is a bit hard to guess what might be happening.
Could you post what your ValueChangeListener is doing ?

I think if it does a setConmponentDataSource() and a few other methods of this kind, the table is reset to default, so the column sizes, … will be reset too.

But… for the weird 3 click thing it might be another problem. Are you using threads to do some background work ? If yes, this
this sticky
.

It is not another thread, and I do not manipulate dataSource.

Here is Trees ValueChangeListener

@Override
            public void valueChange(ValueChangeEvent event) {
                Object item = event.getProperty().getValue();
                if (item == null)
                    return ;
                String tableName = tree.getItem(item).getItemProperty(TREE_PROPERTY_CAPTION).getValue().toString(); // for select query
                contentPanel.setTableName(tableName);
                contentPanel.loadAllData();
            }

and important parts of loadAllData method pseudocode:

private void loadAllData() {
// reset Table
        table.removeAllItems();
        for(String property : properties)
            table.removeContainerProperty(property);
        contentTableProperties.clear();
        
        tableFields = tableDAO.getTableFields(tableName);     // contains field info... name, alias, width, type
        SqlRowSet resultSet = tableDAO.executeQuery(query);
        SqlRowSetMetaData metaData = resultSet.getMetaData();
        
        for(TableField tableField : tableFields) {
            String fieldAlias = tableField.getAlias();
            table.addContainerProperty(fieldAlias, Object.class, null);
            table.setColumnWidth(fieldAlias, tableField.getWidth() );
            properties.add(tableField.getAlias());
        }
 
        while(resultSet.next()) {
//filling table content... like
//    Object item = table.addItem();
//    table.getItem(item).getItemProperty(properties.get(i)).setValue(resultSet.getObject(field.getName());
       }
        
        table.setSortContainerPropertyId(properties.get(0));
        table.sort();
    }

That is all… nothing special… I figured it out that the ratio I was talking earlier is not random. Columns width are set up to contain all data they are filed with. Is there an autoSize options for table columns or something like that? But why third click works?

Your code looks ok.

Can you make a small test app and attach it to a bug report ?
Like this the devs can take a quick look at it and fix the problem.

Forgive me it took so long but I didn’t have much time. So I wrote sample application to show you my problem. Triple click works perfectly (I mean doesn’t work).
12210.java (3.92 KB)
12211.zip (3.59 KB)

Can someone confirm if it is a bug, or am I doing something wrong?

I’m having exactly the same problem as mentioned in the OP where I’m setting the widths for columns (after setting them already once while initializing the table, where they work), but they won’t update before clicking a cell in the table or some other trick such as having a button which calls markAsDirtyRecursive for the table. Calling markAsDirtyRecursive right after setting the widths doesn’t work, tried some other ways that didn’t help eather, and this thread is the closest I found while trying to solve this issue. Anyone else who has been experiencing this still, any ways to get around this?

By the way I’m using Vaadin 7.4.1.