JRichTextEditor
JRichTextEditor copied to clipboard
saving formatted text
hallo. Demo project print, but no save funcion and code is provided. using this project can I save and load a formatted document? if yes in witch format? can I easily replace a JEditorPane with jrichtexteditor? thanks
Hello, I put this on github 9 years ago. Don't use it myself anymore, so I don't know if replacing JEditorPane with JRichTextEditor is simple. JXmlNoteEditor extends JScrollPane. It uses JXmlNotePane, which extends JTextPane.
To be able to save and load the formatted document, you can use the toXml() and fromXml() methods of the XmlNoteDocument class.
The XMLNoteDocument can be retrieved from JXmlNoteEditor using the method document().
In the demo, the save command, will trigger these lines:
} else if (cmd.equals("save")) {
String xml;
try {
_document.setMeta("last_id", _id);
_document.setMeta("save_time",new Date());
xml = _document.toXML();
} catch (BadDocumentException e1) {
e1.printStackTrace();
xml = null;
}
System.out.println(XMLNoteUtils.prettyPrintXML(xml));
try {
OutputStream sout = new FileOutputStream(_saveFile);
sout.write(xml.getBytes("UTF-8"));
sout.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (UnsupportedEncodingException e3) {
e3.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
xml = _document.getStyles().toXML();
System.out.println(XMLNoteUtils.prettyPrintXML(xml));
It does try to save the document to the file '_saveFile', initially initializes to '_saveFile=new File("/tmp/xmlnote.jxmlnote");'.