Reputation: 155
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
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