'How to add text under an image that display in FlowLayout() in codename one
for (Evenement r : list) {
Container c3 = new Container(new FlowLayout());
Image placeholder = Image.createImage(380, 380);
EncodedImage enc = EncodedImage.createFromImage(placeholder, false);
URLImage urlim = URLImage.createToStorage(enc, r.getImg(), url + "/" + r.getImg());
ImageViewer imgV = new ImageViewer();
imgV.setImage(urlim);
SpanLabel cat= new SpanLabel("Nom de l'evenement :" + r.getNom());
SpanLabel cat6= new SpanLabel(" " );
Label lab= new Label("jjj");
c3.add(imgV);
c3.add(cat6);
add(lab);
Images display in FlowLayout
but I want to add some text under every image. When I add a label with text in it, it appears to the right of the image. Even when I used another Container
and put in the label, nothing is changed.
Thanks in advance.
Just another question: Is it possible to Itext PDF API which I have already used in java, before.
Solution 1:[1]
You need to nest containers by creating a BoxLayout
container on the Y_AXIS
with the image and text then add that to c3
.
Instead of:
c3.add(imgV);
c3.add(cat6);
Do:
c3.add(BoxLayout.encloseY(imgV, lab));
As a side note, notice that you shouldn't use FlowLayout
for things of this type as it's pretty flaky.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shai Almog |