简体   繁体   中英

Display an image in JTextArea

I am trying to write a chat client(multi-threaded) which should be capable of displaying images(sent by server) in the main chat window(JTextArea in my case)? Is there any way to do this directly or do I have to encode and parse back my image. For example Facebook chat lets you directly drag and drop images and displays them in main chat window. If we cannot do this in Java, please suggest some other Environment in which this is doable.

我认为 JTextPane 更适合您的需求: http : //docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html

It works:

JTextPane t = new JTextPane();
t.setContentType("text/html");
t.setText("<html><img src='" + Hello.class.getClassLoader().getResource("hello.gif").toString() + "'/></html>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM