×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Mar 2005
    Location
    Hamburg, Germany
    Posts
    284

    LWUIT Table: last col should

    LWUIT Table: last col should fill space to right

    Hello developers,

    for a game I have a highcore-table.
    It looks like this:

    Rank|Points|Name

    On asha 501 it tries to make the columns as small as possible, leaving empty space to the right.
    I would like it that the last column fills the rest of the available space to the right.

    My table-creation is very simple:
    Code:
     
      TableModel tm = createTableModel();
      table = new Table(tm);
    How can I improve the layout of my table?

    Regards

    Karsten Meier
    Last edited by internetlabor; 2013-10-18 at 11:38. Reason: header was truncated

  2. #2
    Registered User
    Join Date
    Mar 2013
    Location
    Nasik, India
    Posts
    21

    Re: LWUIT Table: last col should

    Am not sure whether it will help you.
    Try to set the width of the table itself to screen width of the device (using setPreferredWidth() )

    Regards,
    Vishal.

  3. #3
    Regular Contributor
    Join Date
    Mar 2005
    Location
    Hamburg, Germany
    Posts
    284

    Re: LWUIT Table: last col should

    Thanks, unfortunately it does not work.
    Also I see that the table has the full width, as there is a border around it, the empty space seem to be inside the table.

    I noticed there is a class TableLayout. But it is not easy to see how it should be used. All its methods are documented perfectly, but the overall usage is missing.

  4. #4
    Registered User
    Join Date
    Mar 2013
    Location
    Nasik, India
    Posts
    21

    Re: LWUIT Table: last col should

    Hi..

    To be honest am not getting what exact table UI you want to display.
    Just try below code which display table of 3 columns of equal size.

    public void showTable()
    {
    Form form = new Form();
    form.setLayout(new BorderLayout());

    Object[][] arrObj = (Object[][]) new Object[3][3];

    TableModel model = new DefaultTableModel(new String[]
    { "Col1", "Col2", "Col3" }, arrObj)
    {

    public boolean isCellEditable(int row, int col)
    {
    return false; // return true if editable cell
    }
    };

    for (int index = 0; index < 2; index++)
    {
    model.setValueAt(index, 0, new String(index + "_1")); // row , column , value
    model.setValueAt(index, 1, new String(index + "_2"));
    model.setValueAt(index, 2, new String(index + "_3"));
    }
    Table table = new Table(model)
    {
    protected Component createCell(Object value, final int row, final int column, boolean editable)
    {

    final Component c = super.createCell(value, row, column, editable);
    c.getStyle().setAlignment(Component.CENTER);
    c.setFocusable(false);
    c.setPreferredW(75); // This should be 1/3 of screen width as we are displaying 3 columns of equal screen width.
    return c;
    }
    };
    table.setScrollable(false);
    form.addComponent(BorderLayout.CENTER, table);
    form.show();
    }

    Regards,
    Vishal.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Location
    Nasik, India
    Posts
    21

    Re: LWUIT Table: last col should

    Hi..

    To be honest am not getting what exact table UI you want to display.
    Just try below code which display table of 3 columns of equal size.

    public void showTable()
    {
    Form form = new Form();
    form.setLayout(new BorderLayout());

    Object[][] arrObj = (Object[][]) new Object[3][3];

    TableModel model = new DefaultTableModel(new String[]
    { "Col1", "Col2", "Col3" }, arrObj)
    {

    public boolean isCellEditable(int row, int col)
    {
    return false; // return true if editable cell
    }
    };

    for (int index = 0; index < 2; index++)
    {
    model.setValueAt(index, 0, new String(index + "_1")); // row , column , value
    model.setValueAt(index, 1, new String(index + "_2"));
    model.setValueAt(index, 2, new String(index + "_3"));
    }
    Table table = new Table(model)
    {
    protected Component createCell(Object value, final int row, final int column, boolean editable)
    {

    final Component c = super.createCell(value, row, column, editable);
    c.getStyle().setAlignment(Component.CENTER);
    c.setFocusable(false);
    c.setPreferredW(75); // This should be 1/3 of screen width as we are displaying 3 columns of equal screen width.
    return c;
    }
    };
    table.setScrollable(false);
    form.addComponent(BorderLayout.CENTER, table);
    form.show();
    }

    Regards,
    Vishal.

  6. #6
    Regular Contributor
    Join Date
    Mar 2005
    Location
    Hamburg, Germany
    Posts
    284

    Re: LWUIT Table: last col should

    Attached an image to see the problem. I want the last column (with title "Name") to be wider. I don't want the other columns to be wider.
    lwuit-table-highscores-asha.png

    I will look into the code above, and also try it with the new asha sdk1.1
    Regards
    Karsten Meier

  7. #7
    Regular Contributor
    Join Date
    Mar 2005
    Location
    Hamburg, Germany
    Posts
    284

    Re: LWUIT Table: last col should fill space to right

    Ok, with help from Vishal I was able to use TableLayout.Constraint

    My current solution:

    Code:
            TableModel tm = createTableModel();  // a method I have written to create a DefaultTableModel from my data 
    
            table = new Table(tm){
                /* override the protected createCellConstraint method */
                protected TableLayout.Constraint createCellConstraint(Object value,
                                              int row,
                                              int column){
                    TableLayout.Constraint c = super.createCellConstraint(value, row, column);  // use the original, what ever this might be
                    if(column == 0){
                        c.setWidthPercentage(15);  // first column 15% wide
                    }
                    else if(column == 1){
                        c.setWidthPercentage(25);  // second column 25% wide
                        // c.setHorizontalAlign(Component.RIGHT);  // this works, but generates space before the column....
                    }
                    else if(column == 2){    
                        c.setWidthPercentage(60);   // last column 60% wide
                    }
                    return c;
                }
            };
            // add table to form, etc...
    This make a table with columns width of 15%, 25% and 60%.
    It is enough for me yet.
    Open issue are:
    1) I needed find out reasonable percentages. These may be different when I translate my app. I would like that the last column just takes the rest of the space.
    I tried to set the last column to 100%, but has lead to smaller first and second column.
    2) Right-Alignment of numbers would be nice. Alignment works, but it again shrinks the cell, and the background get visible left to the cell. See Attachment.
    lwuit-table-highscores--rightalign-asha.png

Similar Threads

  1. OutOfMemoryError in LWUIT Table
    By Javier Muñoz in forum Mobile Java General
    Replies: 4
    Last Post: 2013-07-09, 08:57
  2. How to apply listener to LWUIT table
    By rajan701v in forum Mobile Java General
    Replies: 1
    Last Post: 2011-06-28, 14:15
  3. How to create a combobox inside Lwuit Table
    By neerajj50@gmail.com in forum Mobile Java General
    Replies: 2
    Last Post: 2011-05-18, 06:05
  4. LWUIT Table Scrolling
    By rajan701v in forum Mobile Java General
    Replies: 3
    Last Post: 2011-03-16, 08:56
  5. Dynamic table in Lwuit
    By ingsaurabh in forum Mobile Java General
    Replies: 6
    Last Post: 2011-02-26, 14:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×