I have found the code below that's supposed to help me show and modify a docx file in my program, posted by user3610008 here: Setting the font and style of jeditorpane . I have change the PathToFile in the code by a direct link to a file exp "c:/bonjour.docx". So this file open correctly at the starting of the program but i can not open a new one from the menu. I think that PathToFile has to relate DocxEditorKit and MetaphaseEditorPanel, but the question is how ??? this the code from the link:
DocxEditorKit DEK=new DocxEditorKit;
MetaphaseEditorPanel MEP=new MetaphaseEditorPanel;
MEP.getHTMLTextPane().setEditorKit(DEK);
//Try and Catch blocks of course to read the file
DEK.read(new FileInputStream(PathToFile), MEP.getHTMLTextPane().getDocument(), 0);
getContentPane.add(MEP, BorderLayout.CENTER);
and this is my code:
DEK=new DocxEditorKit();
MEP=new MetaphaseEditorPanel();
MEP.getHtmlTextPane().setEditorKit(DEK);
FileInputStream input=new FileInputStream("d:/bonjour.docx");
try{
DEK.read(input, MEP.getHtmlTextPane().getDocument(), 0);
} catch(BadLocationException ble) {
ble.printStackTrace();
}
You made a field from MEP; maybe you added it earlier, and now on doing MEP = new ...
you are not adding the new MEP object to the JFrame.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.