Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 6:56 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Newline in textarea
PostPosted: Fri Feb 03, 2012 3:16 pm 
Offline
User avatar

Joined: Sat Jan 14, 2012 1:05 pm
Posts: 28
Location: Leipzig, Germany
Hello there.
I feel kinda stupid at the moment...

I created a Textarea with a SimpleTextAreaModel. To set the text to be displayed I use
Code:
mySimpleTextAreaModel.setText("first line\nsecond line");

//works too:
String foo = "bla\nblubb";
mySimpleTextAreaModel.setText(foo);

This works perfectly and displays two lines as expected.

However I have my text stored in an XML file which I deserialize by using a XMLDecoder.
Code:
// [...]
    <void property="weaponDescription">
     <string>Standard assault rifle\nFires a shot of super heated plasma</string>
    </void>
// [...]

What happens now is that the text is displayed but the newline character \n isn't recognized and instead is printed to screen.
I set a debug breakpoint and looked inside my String variable to verify that there isn't any escaping going on but the string looks exactly as in the xml file and therefor should produce a line break.
I looked inside the xml file if there's some weird encoding issue but the newline looks legit (\0x5C \0x6E).
I converted the xml deserialized string to a char array but there's also only a simple newline in there.

Now I'm a little bit lost and hope you guys could shed some light on me.


Attachments:
File comment: ingame view
ingame.jpg
ingame.jpg [ 9.29 KiB | Viewed 307 times ]
File comment: netbeans debug view
debug.jpg
debug.jpg [ 59.74 KiB | Viewed 307 times ]

_________________
team red
Top
 Profile  
 
 Post subject: Re: Newline in textarea
PostPosted: Fri Feb 03, 2012 7:28 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Well - this is not a TWL issues.
If you write \n in a Java source file, then the Java compiler will convert that sequence into a 0x10 (you can look at the generated .class file with a hex editor).
But if you write it in an XML file it is just handled as 2 normal characters. To get a line break in XML just make a line break in the source file like here.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Newline in textarea
PostPosted: Fri Feb 03, 2012 9:47 pm 
Offline
User avatar

Joined: Sat Jan 14, 2012 1:05 pm
Posts: 28
Location: Leipzig, Germany
Ah, thanks. That worked perfectly.

I'll also look into the .class files and probably make some more test to understand why it is how it is.
I find this rather odd. This only happens while using java de-serialization, doesn't it? Need to wrap my head around this tomorrow since I'm too tired atm.

Edit: Ah, nevermind. Got it. I really need some sleep :roll:

_________________
team red


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group