Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am developing an application where, when I select a value(file) from list it should be opened in jTextPane of a different form. I am using two panels one is mainpanel where my list is shown and one is ExcelSheet, when i click on a list value then mainpanel is closed and new form ExcelSheet is displayed but not the content of doc file in jTextPane.

XWPFWordExtractor extractor=null;
    File file=null;
    String str=(String) list.getSelectedValue();
    mainPanel.setVisible(false);
    new ExcelSheet().setVisible(true);
    ExcelSheet obj=new ExcelSheet();
        try {
             file=new File("C:\Users\Siddique Ansari\Documents\CV Parser"+str);   


        FileInputStream fis=new FileInputStream(file.getAbsolutePath());
        XWPFDocument document=new XWPFDocument(fis);
        extractor = new XWPFWordExtractor(document);
        String fileData = extractor.getText();
        Document doc = obj.jTextPane1.getDocument();      

            System.out.println(fileData);
            doc.insertString(doc.getLength(), fileData, null);

    }
    catch(Exception exep){exep.printStackTrace();}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
158 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use Action to encapsulate the code that updates the text pane in order to display a given file. You can invoke the action from a ListSelectionListener added to your JList. You can also use the action in a menu item or a toolbar button, as shown here. ImageApp is a related example.

For example, each instance of your action will need the target text pane and file:

class FileAction extends AbstractAction {

    JTextPane target;
    File file;

    public FileAction(JTextPane target, File file) {
        this.target = target;
        this.file = file;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // render file in target
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...