日期:2014-05-20  浏览次数:20808 次

在Java中,如果想显示图片,该用那个类??
我现在正在写一个聊天室程序(我的期末大作业!),发送框和接受框都是用的JTextArea类的对象,但是我想发送图片!我该用那个累啊??或者该怎么处理啊??

------解决方案--------------------
JEditorPane 关注下这个吧

貌似他可以
------解决方案--------------------
首先不要用jtextarea
用 JEditorPane 
把它设置为 text/html 格式的文本
至于显示图片
不和显示文字的道理是一样的,用io就可以了

------解决方案--------------------
1.
Java code

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)
    {
    }

------解决方案--------------------
你用传送图片字节流,传送过去,先传送一个值提示要接收图片,然后开始接收,对方开始接收图片字节流,完成后软件显示处理显示图片
具体用法:没具体研究过。。。