Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Text Plain and JTextPane  RSS feed

 
Gabry ombo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
I would like to display HTML source code in a JTextPane.
When I set the content type to "text/plain", the JTextPane change from multiline to singleline and all code is displayed only in the first line.
How can i change my code to show the HTML source in a multiline JTextPane ?
Thanks



 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
How does the original html file look when you open it in any text editor? Does it have all indentations and new lines?
 
Brian Cole
Author
Ranch Hand
Posts: 935
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your purpose in messing with HTMLEditorKit? HTMLEditorKit is intended to be used with JEditorPane and is (unless I'm missing something) pointless to use with JTextPane.

The same thing goes for setContentType(). JTextPane inherits that method from JEditorPane, but calling JTextPane.setContentType() pretty much always a mistake.

If you want a plain JTextPane, then simply instantiate one using the zero-argument constructor. (Or use JTextArea if you want something even simpler.) If you want to use HTMLEditorKit (which would be more appropriate for rendering HTML than for displaying HTML source) then use JEditorPane.
 
Brian Cole
Author
Ranch Hand
Posts: 935
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for waking a three-year-old thread. I clicked on it only because it was listed as a "similar thread" at the bottom of the page. I should have checked the date before replying.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!