Abhimanyu Pathania
Abhimanyu Pathania

Reputation: 354

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.

Upvotes: 1

Views: 8519

Answers (2)

dgolive
dgolive

Reputation: 437

It works:

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

Upvotes: 0

Cristina_eGold
Cristina_eGold

Reputation: 1553

I think a JTextPane would suit your needs better: http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html

Upvotes: 3

Related Questions