aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JEditorPane and setContentType Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditorPane and setContentType" Watch "JEditorPane and setContentType" New topic
Author

JEditorPane and setContentType

Damithri Warnakulasuriya
Greenhorn

Joined: Apr 18, 2008
Posts: 17
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

Joined: Jul 26, 2007
Posts: 10255
    
    8

Why are you using the Enter key? HTML will wrap by default. Whenever you want a new line you can use or tags.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Damithri Warnakulasuriya
Greenhorn

Joined: Apr 18, 2008
Posts: 17
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

Joined: Jul 26, 2007
Posts: 10255
    
    8

No idea. Maybe you can switch to JTextArea instead.

Anybody else?
Damithri Warnakulasuriya
Greenhorn

Joined: Apr 18, 2008
Posts: 17
Thanks anyway
Phil Walterson
Greenhorn

Joined: Oct 08, 2004
Posts: 7
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.



 
 
subject: JEditorPane and setContentType