Escape char \n not recognized in Label/TextField/TextArea

24 views
Skip to first unread message

P5music

unread,
Aug 16, 2020, 1:55:12 PM8/16/20
to CodenameOne Discussions
I want a screen in my app that display instructions.
I created the text and put it in a string. That string is in the localization bundle. It has many escaped \n because its text is multiline (it's the same string of the strings resources file in the original Android project of this iOS port).
I see that the escaped characters are written as they are, that is, I see many \n in the text and it's not multiline as it is intended to be read by the user.
I used Label, TextView with same result.TextArea shows nothing.
Thanks in advance

Shai Almog

unread,
Aug 16, 2020, 9:46:34 PM8/16/20
to CodenameOne Discussions
In the designer tool under the localization edit section you have a button at the bottom that allows you to edit multiline text. Just add the line breaks and the string will have them.

SpanLabel and TextArea respect line breaks.

TextArea doesn't implicitly fetch from the bundle though. For it you will need to use the UIManager.localize method. The logic is that you want to localize labels but text components include user input which isn't localized

P5music

unread,
Aug 17, 2020, 1:08:54 PM8/17/20
to CodenameOne Discussions
I am using a special method to Localize strings. My app has keys and some methods to handle them.
String resources are "in sync" with the Android project files, so I would like to mantain the strings with the \n inside.
I have no problems to feed the Text area with a string with replaced "\n". I do not know what I have to put in place of that escape char, or other method to force line breaks.
Maybe I have to create a for loop to append strings?
Thanks in advance.

P5music

unread,
Aug 17, 2020, 1:34:50 PM8/17/20
to CodenameOne Discussions
I addition: I tried SpanLabel and text is multiline, but the "\n" are printed. Maybe this is a bug.
TextArea displays nothing.

Shai Almog

unread,
Aug 17, 2020, 9:52:19 PM8/17/20
to CodenameOne Discussions
It's \n. If you see them it means that myString = StringUtils.replaceAll(myString, "\\n", "\n"); will work.

P5music

unread,
Aug 18, 2020, 3:08:36 AM8/18/20
to CodenameOne Discussions
The original strings in Android resources file had \n and the line-break, because it is not read in Android so it was just a redundancy.
In Codename the line-break is read.
replaceAll(myString, "\n", ""); worked.
Thanks
Reply all
Reply to author
Forward
0 new messages