This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JEditorPane and setContentType

 
Damithri Warnakulasuriya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm using a JTextPane and content type is set to "text/html".
Each line that I have separated by Enter Key is by default within a <P> tag and therefore the content of the JTextPane creates unnecessary spaces between lines.
Does anyone know to ignore those <P> tags or to replace those by <br> tags by setting a property of JTextPane

Thanks

 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the Enter key? HTML will wrap by default. Whenever you want a new line you can use or tags.
 
Damithri Warnakulasuriya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextpane is for user to enter a message and send.
So user uses Enter key when he wants to move in to the next line.

Then ultimately the each new line is wraped by a <P> tag. I want to wrap it by <br>.





 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea. Maybe you can switch to JTextArea instead.

Anybody else?
 
Damithri Warnakulasuriya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks anyway
 
Phil Walterson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damithri Warnakulasuriya wrote:Hi

I'm using a JTextPane and content type is set to "text/html".
Each line that I have separated by Enter Key is by default within a <P> tag and therefore the content of the JTextPane creates unnecessary spaces between lines.
Does anyone know to ignore those <P> tags or to replace those by <br> tags by setting a property of JTextPane

Thanks



This post is a month old, but since I ran into this same issue today I may as well contribute.

I was able to work around this (somewhat) by initializing the JTextPane's HTML like so:




It seems as if by default the JTextPane HTML will have paragraph tags in it, and when it does, adding newlines causes them to spawn all over the place and makes formatting difficult (hence this topic). Without the paragraph tags in the HTML to start with, the behavior becomes more predictable. This solution strikes me as somewhat crude, and you will run into more issues to deal with after doing this.. I may make a more detailed post with the subsequent issues I encountered (with code examples), but for now I wanted to pass this little bit along in the hopes that it might help someone or at least encourage discussion.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic