Center Align Text in TextField

21 views
Skip to first unread message

Mark Bolduc

unread,
Oct 8, 2020, 12:20:43 PM10/8/20
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA Netbeans  12.2
Desktop OS Windows 10 Pro
Simulator latest
Device simulator IOS, Android

Please suggest how to center align a textField with params as below.
Always justifies to RIGHT. LEFT works correctly

            Form hi = new Form("Center Text in TextField", BoxLayout.y());
            TextField txt = new TextField("55565");
            txt.setEditable(true);
            txt.getAllStyles().setAlignment(TextField.CENTER);
            txt.setSingleLineTextArea(true);
            txt.setConstraint(TextField.DECIMAL);
            hi.add(txt);
            hi.show();

Regards

Shai Almog

unread,
Oct 9, 2020, 12:00:40 AM10/9/20
to CodenameOne Discussions
We don't support centering a text field at this time. Only a text area (multiline) and even then not when editing. So when you move to editing mode it will jump to the left/right respectively.

Center text field has a bit of a nuanced behavior and it's hard to replicate it when going back and forth between native editing and lightweight.

Mark Bolduc

unread,
Oct 9, 2020, 8:45:19 AM10/9/20
to CodenameOne Discussions
That works

Seems like it would be same code to center TextField as TextArea,

Odd.

Regards

Shai Almog

unread,
Oct 10, 2020, 1:43:46 AM10/10/20
to CodenameOne Discussions
Not really.
A text field overflows when the text is too long and the center behavior is very inconsistent/challenging. AS text area is slightly more consistent here.

For both we don't support the editing in the center mode.
Reply all
Reply to author
Forward
0 new messages