JTextPane textComp
ImageIcon  ic
textComp.insertIcon(ic);
我这样可以向 textComp  中插入 图片,但是我使用保存  MinimalHTMLWriter htmlWriter = new MinimalHTMLWriter(writer,
                        (StyledDocument)
                        textComp.getDocument());
                htmlWriter.write();
保存的时候却没有办法把  图片的代码部分保存起来
一就是说我只能看到它一次 再次打开他的时候就看不见了
  怎么可以直接向jtextpane 或者jeditorpane中插入html 代码了?
  我使用htmleditorkit  的inserthtml 方法的时候 
HTMLDocument doc=(HTMLDocument)textComp.getDocument() 
在  kit.insertHTML(doc, textComp.getCaretPosition(), "<a text=\"test\" />", 0, 0,
                               HTML.Tag.A);
却不行???

解决方案 »

  1.   

    public void textInertHTML(){
            JTextPane jp = new JTextPane();
            jp.setBounds(20, 20, 300, 100);
            HTMLEditorKit kit = new HTMLEditorKit();
            kit.install(jp);
            this.getContentPane().add(jp);
            String path = "icons/cut.gif";
            try {
                kit.insertHTML((HTMLDocument) jp.getDocument(), jp.getCaretPosition(),
                               "<img src=" + path + "/>", 0, 0, HTML.Tag.IMG);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(InsertHTML.this,
                                              "image not loaded",
                                              "ERROR",
                                              JOptionPane.ERROR_MESSAGE);
            }    }
      

  2.   

    我那只能插入图片
    不晓得哪位知道万能的插入html代码的不