我正在寫一些加載模板html文檔,做一些關鍵字替換,然後打印出來的東西。除了模板中包含圖像以外,這工作正常。如果我瀏覽到模板.html圖像顯示正常(所以我猜路徑正常),但它們在最終輸出中顯示爲空白空間。Swing - 當JEditorPane加載本地html時不顯示本地圖像
HTML模板是一樣的東西:
<html>
<body>
<img src="file://c:/temp/my-logo.png" width="50" height="50"/>
[[[some stuff I want to replace]]]
</body>
</html>
夠簡單。 和加載此模板,像這樣:
public void test() {
JEditorPane text = new JEditorPane("text/html", "default");
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
HTMLDocument htmlDocument = (HTMLDocument)htmlEditorKit.createDefaultDocument();
text.setEditorKit(htmlEditorKit);
// read the html template into the JEditorPane's text
text.read(new BufferedReader(new InputStreamReader(new FileInputStream(new File("path to my template html")))), htmlDocument);
// then do some replacements
text.setText(magicReplacements(text.getText()));
text.repaint();
// and then print job stuff, fire off the job, check if it worked etc...
}
的文本顯示和格式正確,只是從來沒有圖像顯示。 任何人都可以發現有什麼問題嗎?
乾杯。
參見本[Q&A] (HTTP:// stackove rflow.com/q/15052690/230513)和[*使用JEditorPane *顯示圖像](http://www.javaworld.com/javatips/jw-javatip109.html)。 – trashgod 2013-02-26 03:59:59