java-metablelayoutlwuit

LWUIT 1.5 Table - horizontal spanning layout


I am wondering if this is a bug or just my faulty code. I've been trying to render table with some horizontal spanning. This is how it should look like:

enter image description here

In LWUIT 1.4 everything worked correctly. Since 1.5 the table looks like:

enter image description here

My implementation:

DefaultTableModel model = new DefaultTableModel(new String[]{"", "", "", ""}, new String[][]{
                {"Header", null, null, null},
                {"1", "2", "3", "4"},
                {"1", "2", "3", "4"},
                {"String", null, "String", null}});


Table tab = new Table(model, false) {

        protected Component createCell(Object value, final int row, final int column, boolean editable) {
            Component c = super.createCell(value, row, column, editable);
            c.setFocusable(false);
            return c;
        }

        protected TableLayout.Constraint createCellConstraint(java.lang.Object value, int row, int column) {
            TableLayout.Constraint tlay = super.createCellConstraint(value, row, column);
            if (row == 0 && column == 0) {
                tlay.setHorizontalSpan(4);
                tlay.setHorizontalAlign(Table.CENTER);
            } else if (row == 3)) {
                if (column == 0) {
                    tlay.setHorizontalSpan(2);
                    tlay.setWidthPercentage(50);
                } else if (column == 2) {
                    tlay.setHorizontalSpan(2);
                    tlay.setWidthPercentage(50);
                }
            } else if (row != 0) {
                tlay.setWidthPercentage(25);
            }
            return tlay;
        }

    };

Solution

  • The bug (in LWUIT) is triggered by the tlay.setWidthPercentage(50); which you can remove and still get the expected result. It seems the width percentage value doesn't take spanning into consideration which I'm guessing it should.

    You should file a bug for this in the issue tracker, thanks for the bug.