0

我知道我们可以将 html 设置为JTextPane内容类型,然后使用img标记来显示图像,但这里我有以字节为单位的图像数据,img不接受它只需要 url 的字节。那么如何在 JTextPane 中显示该图像?这种情况还有其他解决方案吗?

我尝试将图像临时存储在 Temp 目录中,然后输入它的 url,img但没有成功。

4

1 回答 1

0

唯一的方法是使用JEditorPane而不是 JTextPane。在那里你必须设置HTMLEditorKit。之后,以下 html 应该可以工作(仅适用于绝对路径)。

<html><img src="file:\\c:\images\example.gif" width=200 height=200></img>

更多信息位于http://download.oracle.com/javase/tutorial/uiswing/components/editorpane.html

于 2011-06-02T11:43:46.767 回答