I have a JLabel in the frame which I want to have different images when clicked upon different buttons. Achieving this was easy. Here is the code
ImageIcon icon = new ImageIcon (img);
icon.getImage().flush();
shopBanner.setIcon(icon);
The problem i0,s earlier I was providing full path to the image like C:\Documents\xxx. Now when I tried the jar in some other computer I noticed the images are not used, that was obvious as the path assigned doesn't exist in other computer.
Back at project I have 2 packages, one for images called images and other for source files called smartshopping. I tried using couple of code but was not able to call the image from the package "images". Please help me fixing the problem. The project works fine in "my" computer if I provide full path as C:/Docs....
Here is the code
Image img = ImageIO.read(getClass().getResource("images/bb-banner-main.jpg"));
ImageIcon icon = new ImageIcon (img);
icon.getImage().flush();
shopBanner.setIcon(icon);
I even tried
URL img= this.getClass().getResource("images/icon.png");
ImageIcon imageIcon = new ImageIcon(img);
//icon.getImage().flush();
shopBanner.setIcon(imageIcon);
Nothing working as of now. What am I doing wrong. Package of image is named images.