I am trying to create a ListCellRenderer that consists of three text areas. In the constructor, I create an empty Container, set its layout, set Styles for the Text area and add the text areas to the container. This container id further added to the renderer component. Further, I am setting values to my TextAreas in the getListCellRendererComponent() method. Following is my code:
class PropertiesRenderer extends Container implements ListCellRenderer<PropertyAssessmentData> {
private TextArea name = new TextArea("");
private TextArea assessedValue = new TextArea("");
private TextArea address = new TextArea("");
private Label focus = new Label("");
public PropertiesRenderer() {
setLayout(new BorderLayout());
Container con = new Container(new BoxLayout(BoxLayout.Y_AXIS));
con.getStyle().setBorder(Border.createBevelRaised());
name.setEditable(false);
name.getStyle().setBorder(null);
con.addComponent(name);
assessedValue.setEditable(false);
assessedValue.getStyle().setBorder(null);
con.addComponent(assessedValue);
address.setEditable(false);
address.getStyle().setBorder(null);
con.addComponent(address);
addComponent(BorderLayout.CENTER, con);
}
public Component getListCellRendererComponent(List list, PropertyAssessmentData value, int index, boolean isSelected) {
name.setText("Name: " + value.getOwner_Name());
assessedValue.setText("Total Value: " + value.getTotal_Value());
address.setText("Address: " + value.getAddress());
return this;
}
public Component getListFocusComponent(List list) {
return focus;
}
}
Now the problem is that it displays everything properly till the text area's have a single row. Once the text area's have multiple rows, it starts hiding the components. I think this has got something to do with CN1 calculating the size of the component without knowing the data it will contain and hence it defaults. Is this true ? Is there a workaround ? Attached is a screen shot
Renderers have uniform sizes I explained a bit more about why this is the case in a blog I wrote earlier this week: https://www.codenameone.com/blog/deeper-in-the-renderer.html
If you need more flexibility I suggest just using a container with box layout Y.