This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image in JTextArea.....need help" Watch "Image in JTextArea.....need help" New topic
Author

Image in JTextArea.....need help

Preethi Mohan
Greenhorn

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

Joined: Nov 22, 2008
Posts: 18944
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

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.
Thanks,
Preethi
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 .

regards
Deekasha
 
 
subject: Image in JTextArea.....need help
 
Similar Threads
Printing on JTextArea
Writing To A JTextArea
Code to print , rotate, zoom an image from an applet
Printing on JTextArea
JTextArea in JTable