Frage

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?

War es hilfreich?

Lösung 2

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.

Andere Tipps

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?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top