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
posted
0
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
posted
0
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
posted
0
hi Preeti, Why don't u use JTextPane. it's inserticon() method will do exactly what u want .