Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

text wrapping in JTextPane when content type html / need a <p> tag

843807Jun 10 2010 — edited Jun 14 2010
Hi, I am having problem with my JtextPane which has content type as "text/html". I initialize my text pane with "<html><head></head><body>"+"<p face =\"courier\" ; size = \"med\"></p>" +"</body></html> so that for each line i have a <p> tag. I convert this html to a XML which is used for printing purpose. My XSLT converts each p with <TextMSG> tag.

After writing a line when I hit enter a new <p> starts which I really need. Now I am having a scenerio when text typed goes beyond the size of the pane it wraps and text automatically goes to next line but no <p> tag inserted which really creates problem for me. On the text pane it shows 2 different lines but after printing it is just one line. For example if I write "My name is Sadd Hossain" and hit enter and write "I love my work" I get the following html:

<html>
<head>
</head>
<body>
<p face="courier" size="med">
My name is Sadd Hossain
</p>
<p face="courier" size="med">
I love my work
</p>
</body>
</html>

But if I just continue writing and dont hit an enter after writing "My name is Sadd Hossain" and continue writing "I love my work", editor pane breaks after Hossain and goes to the next line but does not insert a <p> tag. So the html in this case I get is :

<html>
<head>
</head>
<body>
<p face="courier" size="med">
My name is Sadd Hossain I love my work
</p>
</body>
</html>


This creates inconsistancy in my application as user complanes that they have seen 2 lines in editor but printed one line.

QUESTION:
Could anybody suggest me how could I set the text pane to insert a <p> tag when it wraps and goes to second line as it does in the case of the second line after hitting "Enter" from keyboard. Your help will be really appreciated. Thank you.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2010
Added on Jun 10 2010
7 comments
522 views