How to put image in jFrame or Swing application?
To place image on swing application you can use jLabel for that. If you are not using any IDE here is code for you.
private javax.swing.JLabel jLabel1; jLabel1 = new javax.swing.JLabel(); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon_128.png"))); //Here image placed in package/folder called images. For better explanation read the whole article.
Now lets roll to IDE Netbeans. Netbeans implement same as above i wrote.
Step 1 : Create package/folder in project that contains images for your project.
- Why is required so? : Say if you are building application for your client that requires images in that. Pointing image out of project folder will not be available in client's computer. So by placing/binding images within project will always available in *.jar file.
Step 2 : Create or place jLable in jFrame.
Step 3 : Open up jLabel properties and browse icon.
Step 4 : Select desired image either way from package (Recommended) or external image.