AndroidHustle AndroidHustle - 8 months ago 42
Java Question

setColumnWidth() doesn't seem to work

I'm developing a webapplication in the Vaadin framework.
I have a table with 14 columns. The last column holds three icons and a problem I'm having is that like half of the time the table is rendered the icon furthest to the right will be "cut in half" vertically. To avoid this problem I tried to set a fixed width to this column that I think would eradicate the problem, however, nothing happens..

I'm using the conventional approach:

simCardTable.setColumnWidth(actionColumn, 135);

However, no matter what value I set to be the column width the column stays the same... Does anyone know why this is? Is it because it's the last column to be added and therefore there's no space to spare..?

Btw, that is the only column I set a specific width to, all of the restoring columns have a the standard width specified by the width of the column header or the cell content.

Any help would be very appreciated!

Answer Source

As i understand from your question ("The last column holds three icons") you use ColumnGenerator to create this last column, with icons. If I right, it mean that you created some sort of custom layout with this icons inside, in this case for you should work this:

final ColumnGenerator generator = new ColumnGenerator() {
            private static final long serialVersionUID = 1L;

            public Component generateCell(Table source, final Object itemId, Object columnId) {
                final HorizontalLayout layout = new HorizontalLayout();

                Embedded icon1 = new Embedded();
                Embedded icon2 = new Embedded();
                Embedded icon3 = new Embedded();

                //Add some themeresource to embedded components

                //Do some listners to this icons


                //Set column with
                setColumnWidth(columnId, 100);

                return  layout;