whywhy
whywhy

Reputation: 155

Add background into JPANEL in JAVA Eclipse

I tried to add background image from internet into my JPanel, but there is source only for add JFrame background and don't have any source for add JPanel background. Please Help.

I tried the Image image= ImageIO.read(new File("resources/2.png")); also but still failed.

My Jpanel Code:

    contentPane = new JPanel();
    contentPane.setBackground(new Color(32, 178, 170));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);;

Upvotes: 0

Views: 233

Answers (1)

joey rohan
joey rohan

Reputation: 3566

Use a Jlabel and add image to it. Something like this :

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/yourImage.jpg")));

And add label to your panel.

Upvotes: 1

Related Questions