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.
Asked
Active
Viewed 8,046 times
1
-
1http://stackoverflow.com/questions/7092491/displaying-an-image-on-a-jtextarea-within-a-jpanel – Nico May 27 '13 at 22:37
-
1I'm not sure you can go this with JTextArea, but you can with JTextPane, check out [this](http://stackoverflow.com/questions/8675482/insert-a-picture-into-a-jtextpane-by-clicking-insert) and [this](http://stackoverflow.com/questions/9993424/how-to-add-images-in-jtextpane) for more details – MadProgrammer May 27 '13 at 22:44
2 Answers
3
I think a JTextPane would suit your needs better: http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html

Cristina_eGold
- 1,463
- 2
- 22
- 41
0
It works:
JTextPane t = new JTextPane();
t.setContentType("text/html");
t.setText("<html><img src='" + Hello.class.getClassLoader().getResource("hello.gif").toString() + "'/></html>");

dgolive
- 425
- 3
- 8