Say I set the text on a JTextPane with code like
JTextPane textPane = new JTextPane();
textPane.setContentType("text/html");
String text = "Some <b>html</b> text...";
HTMLDocument doc = (HTMLDocument) textPane.getDocument();
HTMLEditorKit editorKit = (HTMLEditorKit) textPane.getEditorKit();
try {
doc.remove(0, doc.getLength());
editorKit.insertHTML(doc, 0, text, 0, 0, null);
} catch (BadLocationException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
I want to be able to get the same text back that I put in such that I can do something like this:
String returnedText = textPane.getText(); // or whatever
if ( text.equals(returnedText) ) {
System.out.println("I want this to be executed");
}
Is this even possible? Are there any methods classes that can help with this? Or is it always the case that the text I set is modified and I can never get back what I put in.