Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image in JTextArea.....need help

 
Preethi Mohan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to know if i can paint/print an image on the JTextArea.
There are methods like createImage(..),prepareImage(..),setPixels(..),drawImage(..) and many more. I want to know if it is possible with the above mentioned methods.
I am basically trying to print the smileys onto the JTextArea in my chat program. JTextArea is placed in a JFrame.I also tried to set the JTextArea as a window by using SwingUtilities.windowForComponent(Component) method which returns a window object. But no change.

If anybody could just tell me how i can add pictures to JTextArea (like smileys in Messenger), I would be very grateful.
Thanks a lot,
Preethi
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to draw on a JTextArea using
<PRE>
JTextArea myArea = new JTextArea();
myArea.getGraphics().drawImage(...
</PRE>
You will have to pick the appropriate drawImage for what you want to do. But I'm not sure that this will solve your problem, because I don't know how an image will behave when scrolling the JTextArea.
 
Preethi Mohan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already tried that, i do get the image in the textarea, but it only remains for a second. The image is not retained in the JTextArea. It only blinks. Is there someway i can retain it on the JTextArea.
I used update(),repaint(),paint()...but couldn't get it.
Any idea, how it can be retained.
Thanks,
Preethi
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Preeti,
Why don't u use JTextPane. it's inserticon() method will do exactly what u want .

regards
Deekasha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic