File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Image in JTextArea.....need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image in JTextArea.....need help" Watch "Image in JTextArea.....need help" New topic

Image in JTextArea.....need help

Preethi Mohan

Joined: Dec 09, 2000
Posts: 4
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,
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You should be able to draw on a JTextArea using
JTextArea myArea = new JTextArea();
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

Joined: Dec 09, 2000
Posts: 4
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.
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
hi Preeti,
Why don't u use JTextPane. it's inserticon() method will do exactly what u want .

I agree. Here's the link:
subject: Image in JTextArea.....need help
It's not a secret anymore!