how to put Image on JPanel using Netbeans

60,844

Solution 1

Have a look at this tutorial: Handling Images in a Java GUI Application

At the same time you could code as well:

JPanel panel = new JPanel(); 
ImageIcon icon = new ImageIcon("image.jpg"); 
JLabel label = new JLabel(); 
label.setIcon(icon); 
panel.add(label); 

Solution 2

You can use ImageIcon and JLabel:

ImageIcon icon = createImageIcon("image.gif", "sample image");

// Label with text and icon
JLabel label1 = new JLabel("Image and Text", icon, JLabel.CENTER);

// Label with icon only
JLabel label2 = new JLabel(icon);

// Add to your JPanel
panel.add(label1);
panel.add(label2);

Solution 3

1) First Paste the image to the Application folder 2) Add a label to the panel 3) Right click label-> Properties 4) Select Icon-> more option 5) Select Package and File and Click oK 6) U R DONE :)

Solution 4

You have to set a JLabel with your icon property set to the picture. For a more detailed solution to the particular problem, go to

http://www.netbeanstutorials.com/p/handling-images.html

There's even a video how to do it there in case you need it.

Share:
60,844
Wern Ancheta
Author by

Wern Ancheta

Updated on June 26, 2020

Comments

  • Wern Ancheta
    Wern Ancheta almost 4 years

    And how do I put Image on a JPanel using Netbeans?