• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextPane ignoring new lines when text is loaded from servlet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a problem with new line character when passing a string I get from a servlet to JTextPane.

There's a text file on server that contains:



I have a servlet that returns the content of this file as a string. When I test servlet in a web browser it prints text in new lines correctly. But when I load it in my swing application and pass it to my textpane it looses new lines character and I get:


Of course I tried to load text directly from a file to a textpane and it loads ok (with new lines).

Servlet Code:

Reading text from file (simplified):


sending text:


My app code:


Please help me on this.
Martin
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the content type of your JTextPane? If it's text/html then that ignores whitespace mostly. Try setting it to text/plain.
 
Martin Syska
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:Try setting it to text/plain.



I tried it but it didn't help.
Also when I open file that I saved on disk using this servlet (It works both ways) in notepad I don't have new lines, but when I open the same file in WordPad everything is ok.

I pass data to servlet this way (utf-8 encoding):
 
Rob Spoor
Sheriff
Posts: 22787
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Syska wrote:Also when I open file that I saved on disk using this servlet (It works both ways) in notepad I don't have new lines, but when I open the same file in WordPad everything is ok.


That's because notepad is garbage; it can only handle \r\n as line breaks; \n alone will not work. Just about every other text editor is better.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic