The following program has a JFrame which contains an image, JTextArea and and a textfield. How can I display the image inside the text area? I will be grateful for any help!

Thank you!

import javax.swing.*;
import java.awt.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.awt.event.*;

public class FrameTest extends JFrame
   private JTextArea area;
   private JScrollPane pane;
   private JTextField field;
   private BufferedImage image1;    

   public FrameTest()
         try {
                     image1 = ImageIO.read (FrameTest.class.getResource("icon.jpg"));

        catch (IOException e)
            { }

       setLayout (new FlowLayout());
       field = new JTextField (20);
       area = new JTextArea (10, 10);

       pane = new JScrollPane (area );

       setSize (500, 500);



    public void paint (Graphics g)
        super.paint (g);
        g.drawImage ( image1, 0, 200, this);
    public static void main (String args[])
        new FrameTest();

I don't know of any way. Text areas are for text. A JTextPane can display images and text.

This article has been dead for over six months. Start a new discussion instead.