3

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;
        }

    };
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hajhet
  • 33
  • 2
  • hi, How to remove the border lines in table model. I used (Tabel table.getStyle().setBorder(null);). It remover border lines only, not cell border. – selladurai Apr 28 '12 at 11:05

2 Answers2

1

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks for the answer! It works better without tlay.setWidthPercentage(50). Table structure is well rendered, but width percentages are inexact. – hajhet Aug 23 '11 at 23:09
  • Try setting the margin/padding of everything to 0 to make sure that none of these are getting in the way. Since percentages are used (not pixels) we can't guarantee 100% accuracy which doesn't make much sense when targeting multiple device resolution. However, if its noticeable then please file an issue in the issue tracker. Thanks. – Shai Almog Aug 24 '11 at 03:14
0

I added this line

TableLayout.setDefaultColumnWidth(1);

before

Table tab = new Table(model, false) {
...

and it worked out.

Ali Ghanavatian
  • 506
  • 1
  • 6
  • 14