File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTextPane Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextPane Questions" Watch "JTextPane Questions" New topic

JTextPane Questions

Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

Hi Guys

We're trying to build a simple WYSIWYG HTML editor using a JTextPane. I've used Charles Bell's example as a reference. My biggest gripe with it at the moment is that bullets aren't working as I would expect them to. If I highlight text and click the "Bullet" button, I want a bullet to be placed immediately before the highlighted text, on the same line. If I try to do this, my code is creating bullets, but it moves the selected text one line down. I've gone through the Oracle tutorial on text components, but I couldn't find anything that helped me with this particular issue.

Also, if I copy and paste text into my JTextPane, the pasted text always appears on a new line (a new <p></p> tag in the actual HTML). Is there a way to prevent the JTextPane from creating new paragraphs?

Lastly, I'm flabbergasted as to why my buttons actually work. I can't see anything that explicitly links my buttons to my HTMLEditorKit or my JTextPane. Short of a little voodoo priest living under my keyboard, how on earth do my buttons/actions know that they should update the JTextPane?

The code is as follows;

I'd really appreciate your inputs on this.


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

FYI, I have cross-posted my question on the Oracle forums, here;
I agree. Here's the link:
subject: JTextPane Questions
It's not a secret anymore!