Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading image in a JPanel

I have a JPanel (which I created using netbeans)and I need to load image in it, based on selection on previous page. Could anyone suggest how to do that. Also is JPanel the best way to do what I am trying to do, or I could do something else ?

Efforts appreciated thanks!!

like image 823
koool Avatar asked Aug 20 '26 17:08

koool


2 Answers

The easiest way to display an image is to use a JLabel and call its setIcon method (or its constructor). The icon can be loaded using one of the constructors of the ImageIcon class.

See http://download.oracle.com/javase/tutorial/uiswing/components/label.html for an example.

like image 127
JB Nizet Avatar answered Aug 22 '26 07:08

JB Nizet


There are number of ways to read/load images in Java. Take a look at this tutorial.

like image 35
KV Prajapati Avatar answered Aug 22 '26 08:08

KV Prajapati



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!