How to create simple buttons with text wrap in BoxLayout.y ?

16 views
Skip to first unread message

P5music

unread,
Jun 7, 2021, 4:12:35 PM6/7/21
to CodenameOne Discussions
There are only two Buttons with a round border over my CN1 app.

I have an issue with the two buttons. I did not realize it before because they had no border and no bg.

I put them in a BoxLayout.y() container along with other components.
They are in different places of the vertical container but it does not matter.

They are horizontally centered, while one would expect they are on the left.
But this is good for me because I want those buttons to be centered.

The issue is that they are huge, the text is centered but the buttons span the entire screen width.

I just want them to be centered buttons that wrap their text.
I also tried enclosing each of them in a BorderLayout container but its the same.

Maybe I forgot some silly thing, but I do not know.

Thanks in advance

Javier Anton

unread,
Jun 7, 2021, 6:00:58 PM6/7/21
to codenameone...@googlegroups.com
Option 1. Add them to a flowlayout container and add that container to the boxlayout.y
Option 2. Override calcPreferredSize and set them to a custom width

There are more ways

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/de82d9d6-a2fe-4ebd-89a5-08f99c5f11c3n%40googlegroups.com.

P5music

unread,
Jun 8, 2021, 2:26:44 AM6/8/21
to CodenameOne Discussions
Thanks
I already tried with FlowLayout and the size is correct, but the button is on the left.
So I added the FlowLayout container to a BorderLayout in the CENTER position, but the button still is on the left.
Regards

Javier Anton

unread,
Jun 8, 2021, 3:53:29 AM6/8/21
to codenameone...@googlegroups.com

Shai Almog

unread,
Jun 8, 2021, 9:18:19 PM6/8/21
to CodenameOne Discussions
I don't understand how you expect this to work?
You have a button with long text that breaks lines. How do you expect this to be centered?
If you explicitly line break with \n then there will be room for centering.

Alternatively just use a bit of margin on the side to limit the space available for the buttons and form the effect of centering.
Reply all
Reply to author
Forward
0 new messages