Reputation: 1084
Here is my code.
editPane
is a JEditorPane.
HTMLKit
is a HTMLEditorKit assigned to editPane
.
try
{
HTMLKit.insertHTML(
(HTMLDocument) editPane.getDocument(),
editPane.getCaretPosition(),
"test", 0, 0, HTML.Tag.B);
}
catch (Exception exc)
{
// TODO Auto-generated catch block
exc.printStackTrace();
}
System.out.println(editPane.getText());
I started with the text [hello].
I expected to see the text [hello test].
However, the bold text was not inserted. How do I make it do what I want?
Upvotes: 1
Views: 235
Reputation: 324108
Try:
String text = "<b>bold";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
System.out.println( textPane.getText() );
or
String text = "<b>bold";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, HTML.Tag.B);
System.out.println( textPane.getText() );
The output from the text pane will show you what the difference is between using "null" or the HTML tag.
I don't really understand the functionality of the last 3 methods of the method.
Upvotes: 1