1

I have been researching this topic a lot and haven't found anything that tells me I can add a BufferedImagento a JTextArea or JTextField. I am making a chat application and trying to add smiley faces for the chat. What I am trying to do is put the image right next to the string like it is text. I was thinking if you could put the Buffered image in the format of a char that would help. Please help me! Thank you!

Rodrigo Guedes
  • 1,169
  • 2
  • 13
  • 27
  • 1
    You may be able to accomplish some of what you're looking for by using an instance of JEditorPane and having a text/html content type set on it. See http://stackoverflow.com/questions/8388489/jtextpane-or-jeditorpane-for-a-chatroom – Marc Baumbach Jan 15 '13 at 16:50

2 Answers2

2

I'd also give a try to JEditorPane. For motivation see: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html.

I've noticed that most of the chat applications, show you what you and others wrote in one window (could be JEditorPane with all the smilies displayed as pics) and bellow you can have editable JTextArea showing just text.

Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81
  • I am aware of that, but I have so much of my code already with the JTextArea and JTextField and was wondering if there were any other options before I switched everything over – user1978786 Jan 15 '13 at 17:57
  • *"wondering if there were any other options before I switched everything over"* No. Not when it comes to 'options for plain text components to display images. It might be possible to come up with an extended component that supports it, but it would only be less coding to make (and time to debug) if you had ***thousands*** of separate instances. – Andrew Thompson Jan 16 '13 at 01:33
0

The problem is that JTextArea and JTextField, are really only meant to show text, in order to implement something that mixes thetext with images, you would need to extend JTextArea and modify the paintComponentMethod to do custom rendering.