swing - Java JTextPane RTF Save -
i have following code trying save contents of jtextpane rtf. although file created in following code empty!
any tips regarding doing wrong? (as usual dont forget im beginner!)
if (option == jfilechooser.approve_option) { //////////////////////////////////////////////////////////////////////// //system.out.println(chooser.getselectedfile().getname()); //system.out.println(chooser.getselectedfile().getabsolutefile()); /////////////////////////////////////////////////////////////////////////// styleddocument doc = (styleddocument)textpanehistory.getdocument(); rtfeditorkit kit = new rtfeditorkit(); bufferedoutputstream out; try { out = new bufferedoutputstream(new fileoutputstream(chooser.getselectedfile().getname())); kit.write(out, doc, doc.getstartposition().getoffset(), doc.getlength()); } catch (filenotfoundexception e) { } catch (ioexception e){ } catch (badlocationexception e){ } }
edit: htmleditorkit if use htmleditorkit works , thats wanted. solved!
if (textpanehistory.gettext().length() > 0){ jfilechooser chooser = new jfilechooser(); chooser.setmultiselectionenabled(false); int option = chooser.showsavedialog(chatgui.this); if (option == jfilechooser.approve_option) { styleddocument doc = (styleddocument)textpanehistory.getdocument(); htmleditorkit kit = new htmleditorkit(); bufferedoutputstream out; try { out = new bufferedoutputstream(new fileoutputstream(chooser.getselectedfile().getabsolutefile())); kit.write(out, doc, doc.getstartposition().getoffset(), doc.getlength()); } catch (filenotfoundexception e) { } catch (ioexception e){ } catch (badlocationexception e){ } } }
here solution. works if htmleditorkit used.
Comments
Post a Comment