0

I have j2me LWUIT app that uses a list. Each cell in the list contains an image and a text area. The TextArea will not grow. I read that in a List all cells must be uniform size, so I should use ContainerList.

With ContainerList I am having the same problem! My TextAreas will not grow. Here's where I create the TextArea:

    TextArea caption = new TextArea();
    caption.getStyle().setBgTransparency(255);
    caption.getStyle().setBgColor(0x060507);
    caption.getStyle().setBorder(null);
    caption.getStyle().setFgColor(0xf0f0f0);
    caption.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
    caption.getStyle().setMargin(0,10,10,10);

    caption.setText(m.caption_text);
    caption.setGrowByContent(true);
    caption.setSingleLineTextArea(false);
    cellCon.addComponent(caption);

cellCon is a vertical BoxLayout. Even if I remove the image, still they will not expand. If I change cellCon to use a BorderLayout and place the image NORTH and the TextArea SOUTH, the TextArea does expand, but overlaps the image (as though it's still trying to maintain a uniform height).

I am creating the ContainerList like this:

list = new ContainerList(new BoxLayout(BoxLayout.Y_AXIS),new DefaultListModel(data));

How do I make this work?

James Harpe
  • 4,315
  • 8
  • 47
  • 74
  • If you want to make another question put it in a new Thread – Mun0n Sep 24 '13 at 07:26
  • And a question for you. Why are you using ContainerList? The simple list doesn't fit with your UI? – Mun0n Sep 24 '13 at 07:39
  • Thanks for your response. Apparently, List requires that each cell be the same height. Obviously, this won't work for TextAreas of variable size. I will try some of the suggestions in your answer later when I have a chance. – James Harpe Sep 24 '13 at 12:16
  • Ok, I will wait for your response....good luck! – Mun0n Sep 24 '13 at 13:32

2 Answers2

0

You can try this 2 ways, by separate or combinaned.

Try to set the text for the TextArea in the constructor of the component. I mean

TextArea caption = new TextArea(m.caption_text);

It usually works fine when you set the text in the constructor. The size of the TextArea resize as it should. If you don't want to use this. You can create the TextArea and set after, the rows and columns with setRows(), and setColumns(). I don't know why, but the TextArea resize doesn't work very well.

The other recommendation is, can tyou try to set the layout to BorderLayout, setting the image in the center and the text in the south?

Mun0n
  • 4,438
  • 4
  • 28
  • 46
  • Setting the text in the constructor doesn't seem to make a difference – James Harpe Sep 24 '13 at 17:29
  • When I do your BorderLayout suggestion, the TextArea does expand, but appears to expand upward, covering part of the image. How much of the image is covered depends on the number of lines...it seems that the last line of the TextArea is always right below the image, where I would want the first line to be. This is what initially made me think that the List or ContainerList was forcing a uniform cell height. – James Harpe Sep 24 '13 at 17:32
  • If you want to have a list with different height in the elements, don't use a list component. Create containers and put them in a BoxLayout Y. Is the only way to set elements with differents heights – Mun0n Sep 24 '13 at 18:11
  • It is not the only way. Right now I have a ContainerList sort of working by calling setRows() on the TextAreas manually based on the charsWidth of the text. Doing this gives me variable size cells. What I don't understand is why the TextArea won't grow by itself like it's supposed to. – James Harpe Sep 25 '13 at 17:17
  • The autoresize of the text area is a lwuit bug....take a look on the nokia forums – Mun0n Sep 26 '13 at 08:58
0

Apparently growByContent does not work in ContainerList. I ultimately had to abandon ContainerList, instead using a Container of components. In this context, growByContent works fine.

James Harpe
  • 4,315
  • 8
  • 47
  • 74