Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Image Icon in Panel

Tags:

java

swing

I want to set an image icon in a panel.I am trying to do like this ;

 JLabel label = new JLabel(new ImageIcon("logo.jpg"))
 panelHeader.add(label);
 add(panelHeader);

But the image is not showing.Any suggestion what i am doing wrong?

like image 472
sohel14_cse_ju Avatar asked Aug 05 '26 01:08

sohel14_cse_ju


1 Answers

The new ImageIcon() constructor just creates an uninitialized image icon. You must invoke the createImageIcon() method that returns ImageIcon source to assign to your also created ImageIcon object.

ImageIcon icon = createImageIcon("logo.jpg", "my logo");
JLabel label = new JLabel(icon);
like image 148
miqbal Avatar answered Aug 06 '26 15:08

miqbal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!