0

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(); 
}
Community
  • 1
  • 1
Mustafa
  • 1
  • 2
  • What happens when you try to open a new file? Error message? According to MetaphaseEditorPanel the openButtonActionPerformed() function just reads the file directly. – Peter Quiring Jul 13 '14 at 12:02
  • PK !f7 [Content_Types].xml.. that's all what i get. I do not know what it means, with no errors – Mustafa Jul 13 '14 at 12:37
  • When i click on open button, I get the dialog window, also no other button works when editing a new text. – Mustafa Jul 13 '14 at 12:46
  • How do you get that PK!F7 value? Do you print it somewhere? Show source. And when you click on open and get the dialog window, does it work? Need more details. Take some screen shots and post them. – Peter Quiring Jul 14 '14 at 14:02
  • PK !f7 suggests you are seeing the binary contents a zip file (ie without unzipping it). – JasonPlutext Jul 14 '14 at 21:57

1 Answers1

0

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.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • I think he's showing what the example does and then in the 2nd snippet what he does. – Peter Quiring Jul 14 '14 at 14:03
  • I minimize my code to this one bellow, now I remove DocxEditorKit, so all tools works very well with html format: opening, editing, saving ... – Mustafa Jul 14 '14 at 14:30
  • MetaphaseEditorPanel MEP;MEP=new MetaphaseEditorPanel();pano.add(MEP,c); – Mustafa Jul 14 '14 at 14:32
  • But what i need is working with docx files not html, I think that MetaphaseEditor do work with docx files. – Mustafa Jul 14 '14 at 14:35
  • So there is only one single `new MetaphaseEditorPanel();`? – Joop Eggen Jul 14 '14 at 14:40
  • Yes, I get it, my code has some contradictions, but actually I work with a single code, simple editor nothing but one MetaphaseEditorPanel initialized then add to a JPanel. and like that it works perfectly with html files, but still that was not what I like, it's docx my need. – Mustafa Jul 15 '14 at 09:51
  • An EditorKit makes a StyledDocument and acts as factory for components, like images. And I/O for the specific format like HTML or docx. By contract a JTextPane + DEK should work. Maybe `setEditable(false)` in case of HTML like rendering. Personally I converted docx to HTML and used that in a JTextPane: HTMLEditorKit. – Joop Eggen Jul 15 '14 at 10:37