Skip to main content

Help with rendering a list like a table

5 replies [Last post]
technolgia
Offline
Joined: 2009-03-09
Points: 0

Hello All,

I am trying to render a list like a table and it works fine. I would want the height of each row to be set to the height of the cell which contains the maximum text in that row. My renderer code is as below:

<code>

public class TableListRenderer extends Container implements ListCellRenderer {

private TextArea[] valueLabel;

public TableListRenderer(int screenWidth, Vector tableHeaders) {

super(new BoxLayout(BoxLayout.X_AXIS));

// prepare the column labels

int tableColumnsize = tableHeaders.size();

valueLabel = new TextArea[tableColumnsize];

for (int index = 0; index < tableColumnsize; index++) {

valueLabel

= new TextArea();

valueLabel

.setEditable(false);

valueLabel

.getStyle().setMargin(0, 0, 0, 0);

valueLabel

.setPreferredW((((TableHeaderValues) tableHeaders.elementAt(index)).getHeaderWidth() * screenWidth) / 100);

valueLabel

.getStyle().setBorder(Border.createEmpty());

valueLabel

.setGrowByContent(true);

addComponent(valueLabel

);

}

</code>

In my getListCellRendererComponent method i set the text to the text areas. Though i have specified setGrowByContent(true) the text area's height does not expand. Can someone kindly help me with this?

Thanking you,

Regards,

S.A.Norton Stanley

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

When creating the text area give it more columns and 2 rows to give it a headstart on growing. E.g. new TextArea(2, 20);

technolgia
Offline
Joined: 2009-03-09
Points: 0

Hi,

The text area still does not grow in height. My output is as in the image below:

Kindly help.

vprise
Offline
Joined: 2003-11-07
Points: 0

I noticed you are also using the setPreferredW method which is a bad idea if you want the preferred size to be calculated correctly. It just won't work.

I hope you are also using a recent version of LWUIT and are aware that all rows will increase with the same size. Notice that older versions of LWUIT scanned only a few rows to calculate the preferred size of a row. Newer versions of LWUIT (1.5) allow you to configure the number of rows scanned to determine preferred height.

technolgia
Offline
Joined: 2009-03-09
Points: 0

Hi vprise,

Thank you. The reason i was using the setPreferredW is because i want the width of each column to be calculated dynamically. If i do not specify the setPreferredW my output is as below :

I am using the latest version of LWUIT. Kindly help.

vprise
Offline
Joined: 2003-11-07
Points: 0

I understand that. However, you can't ask LWUIT to calculate a size after you specify a size.

Setting the preferred width implicitly sets the preferred height. Once you do that LWUIT won't calculate the size anymore since you specified it earlier. I would suggest you use a different layout instead. Try using table layout and specifying the width constraint for a specific cell.