Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Text Plain and JTextPane  RSS feed

 
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



 
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?
 
Author
Ranch Hand
Posts: 964
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: 964
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!