Any Help, I need guide/way on how to get Image from JLabel and set it to JTextArea in netbeans when a button is clicked.
I have 3 Object: (1) Jlabel(with an imported picture in it) (2) JTextArea(to store the picture when Button is clicked) (3)A button

I tried using a method:

private Icon Icon;
private Icon Image;
public Icon getImage(){
    return Icon;



S.setText(""+Image); // S is the variable name for the JTextArea

it on captures the file link of the image and displays it in the textArea field when the Button is clicked

A JTextArea is really bad choice of component to display an image - it's specifically designed to display lines of text. Maybe you should re-think your choice of components?
If you explain what you are trying to achieve maybe someone can suggest an easier way to achieve it.

I think the best way to insert would be to insert it as a background image.

JtextArea textArea = new JtextArea(){
  public void paintComponent(Graphics g){
      // the image variable should be replaced with your image
     g.drawImage(image, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);

Edited 3 Years Ago by Galbatorix: forgot super.paintComponent(g);

Thanx for your contribution, actually am working on a project, and the user is expected to input variables, and these variable directed to the TextArea icluding an Image which i imported to the Jframe via JLable, for Printing: my challenge now is getting the Image from the JLabel, and setting it to appear on the JTextArea for onward printing.

Thanks Lena1990, u code really helped, though i realised i could make the image output together with text output, it is always fixed at the centre of the jTextArea on top of the text ouput thereby blocking the text outputted, it was nice knowing that a simple code like dis cld solve my pussle, but am still searching for a better way to output image and text in an formatted format. Thanks

This question has already been answered. Start a new discussion instead.