0

want to horizontally and vertically align my JTextPane's content. I found a good tutorial here, it works very well: http://java-sl.com/tip_center_vertically.html

However if I want to embed HTML code, e.g.

doc.insertString(0,"<html> some text <b> bold text </b> </html>", attrs)

The text won't be rendered as HTML, instead it is treated as simple text.

Some ideas on how to solve this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
matthias
  • 1,938
  • 23
  • 51

1 Answers1

0

try somethings like this

HTMLDocument doc = (HTMLDocument)textPane.getDocument();
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
String text = "<a href=\"abc\">hyperlink</a>";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);

And you dont need a <html /> tag inside.

RaymondM
  • 318
  • 1
  • 10
  • sorry, I can't get it working. If I do it your way the layout will not center the text vertically anymore – matthias Dec 10 '13 at 11:25