1.try { // Get the text pane's document JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument)textPane.getDocument();
// The image must first be wrapped in a style Style style = doc.addStyle("StyleName", null); StyleConstants.setIcon(style, new ImageIcon("imagefile"));
// Insert the image at the end of the text doc.insertString(doc.getLength(), "ignored text", style); } catch (BadLocationException e) { } 或JTextPane.insertIcon(icon); 2.直接把图片当作文件来读,转成BYTE传就行了.
楼主截止到2008-06-21 07:51:17的汇总数据:
注册日期:2008-1-2
上次登录:2008-6-21
发帖数:1 发帖分:10
结贴数:0 结贴分:0
结贴率:0.00 % 结分率:0.00 %
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
用 JEditorPane
把它设置为 text/html 格式的文本
至于显示图片
不和显示文字的道理是一样的,用io就可以了
如果是动态的显示的用io
2.想传送图片用IO.
// Get the text pane's document
JTextPane textPane = new JTextPane();
StyledDocument doc = (StyledDocument)textPane.getDocument();
// The image must first be wrapped in a style
Style style = doc.addStyle("StyleName", null);
StyleConstants.setIcon(style, new ImageIcon("imagefile"));
// Insert the image at the end of the text
doc.insertString(doc.getLength(), "ignored text", style);
} catch (BadLocationException e)
{
}
或JTextPane.insertIcon(icon); 2.直接把图片当作文件来读,转成BYTE传就行了.
你可以用io对文件读取啊
至于你要显示图片,你可以用jtextpanel这个类,它支持html语言啊