JAVA ME - LWUIT Table Layout embedded TextAreas

my goal is to display a Table through parsing an XML file.

I'm using a SAX Parser and the content has multirows and I want the table width to fit to the display. Of course Y_AXIS scrolling would be ok.

Right now, I'm using the HTMLTableModel of src/com/sun/lwuit/html/ and it's corresponding HTMLTable. For this I declared it's methods public so I can access them. This works fine so far. This allows me to declare tables without knowing their size prematurely.

To allow multirows, I'm embedding TextAreas in the Cells.

Now the problem: The HTMLTable t needs t.setScrollableY(true), or else not all rows are shown.

This causes the table to be a bit to large in X direction, so the right border isn't shown. Also the bottom border isn't shown all the time.

The container in which the table is embedded has BorderLayout.Y_AXIS. Things I tried: t.setPreferredW(mainContainer.getLayoutWidth()); This does reduce the size of the table, but then the table doesn't show all it's rows, like without t.setScrollableY(true).

t.setLayout(new BoxLayout(BoxLayout.Y_AXIS)) this causes an java/lang/ClassCastException.

Any ideas? Thanks in advance.

Excerpt from my code:

} else if (qName.equalsIgnoreCase("td")) {

                    if (sb.length() > 0) {
                        String sbt = new String(sb);
                        sb.delete(0, sb.length());
                        TextArea c = new TextArea(sbt);
                        c.setEditable(false);
                        c.getStyle().setFont(smallFont);
                        table.addCell(c, false, null);
                    }
                } else if (qName.equalsIgnoreCase("tr")) {
                    debugPrint("Row closed.");
                    table.commitRow();
                } else if (qName.equalsIgnoreCase("table")) {
                    HTMLTable t = new HTMLTable(table);
                    //without scrollable Y not all table rows are shown
                    t.setScrollableY(true);
                    //t.setPreferredW(screenWidth);
                    //this is verboten.
                    t.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
                    mainContainer.addComponent(t);
                    tableBool = false;
This question and answers originated from www.stackoverflow.com
Question by (7/12/2011 7:31:44 AM)

Answer

You can't change the layout of the table from table layout otherwise it will not be a table.

It should be possible to get the table to fill the width of a parent BoxLayout_Y by assigning width percentages to table columns up to 100% e.g. for a 3 column table return assign 33, 33 & 44.

This can be achieved by subclassing table and overriding the method:

protected TableLayout.Constraint createCellConstraint(Object value, int row, int column) {
    TableLayout.Constraint c = super.createCellConstraint(value, row, column);
    c.setWidthPercentage(whateverYouWant);
    return c;
}
Answer by

Find More Answers
Related Topics  java-me  lwuit
Related Questions
  • How to display the multi line textAreas in lwuit (J2ME)?

    I have created a TextArea with statement .... quest1Label = new TextArea(); I am using the textArea for displaying the labels.... So I use following function to set its properties.... priv…
  • HashTable to Lwuit Table

    Hashtable iHashtable=new Hashtable(); iHashtable.put("Name", "Jhon"); iHashtable.put("Address","India"); Enumeration iEnumeration=iHashtable.keys(); while(iEnumeration.hasMoreElement…
  • LWUIT: Layout calculation problem

    I have a rather large application written with LWUIT. With only a few screens that have the problem. The problem: When the page loads, everything looks fine. but when you scroll you can't scro…
  • Dynamic table in lwuit

    How to create a Dynamic table in lwuit TableModel model = new DefaultTableModel( new String[]{"A", "B", "Call Avg"}, new Object[][]{ {"0", "50", "0.00"}, {"0",…
  • LWUIT 1.5 Table - horizontal spanning problem

    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: In LWUIT 1.4 everything worked correct…
  • HashTable to Lwuit Table

    Possible Duplicates: Dynamic table in lwuit HashTable to Lwuit Table Please give me Some example After parsing a JSON String I want to put it in a HashTable,From the HashTable I ge…
  • LWUIT button issue

    import com.sun.lwuit.Button; import com.sun.lwuit.Command; import com.sun.lwuit.Display; import com.sun.lwuit.Label; import com.sun.lwuit.events.ActionEvent; import com.sun.lwuit.events.…
  • Split screen proportionally LWUIT

    I want to split the screen by 30% and 70% vertically, How can i achieve this with lwuit? I used/tried GridLayout but it splits the screen equally. Need a example code for this. Thanks in advance!…
  • LWUIT Scrolling

    Here is another question regarding JavaMe and LWUIT. I need to manually scroll textarea with help of methods or etc. TextArea contains methods responsible only for obtaining current position of s…
  • LWUIT assistance

    import com.sun.lwuit.Button; import com.sun.lwuit.Command; import com.sun.lwuit.Display; import com.sun.lwuit.Label; import com.sun.lwuit.events.ActionEvent; import com.sun.lwuit.events.ActionListen…