Hello,

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);
       area.setLineWrap(true);

       pane = new JScrollPane (area );

       add(pane);
       add(field);
       setSize (500, 500);
       setVisible(true);

       repaint();

    }


    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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.