I have imported a few images in my Netbeans Java project. I want to set one of them as a label's icon when I click a button. I don't want to use the path of the image in the code.
Please help me.
I have imported a few images in my Netbeans Java project. I want to set one of them as a label's icon when I click a button. I don't want to use the path of the image in the code.
Please help me.
If you have imported images in your project then use :
myJLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/yourImageName.jpg")));
And enclose it in the actionListener block of that button.
Refer this to know how to use Jbutton
.