[Q#5287252][A#5287521] how to put Image on JPanel using Netbeans
https://stackoverflow.com/q/5287252
And how do I put Image on a JPanel using Netbeans?
Answer
https://stackoverflow.com/a/5287521
Have a look at this tutorial: Handling Images in a Java GUI Application At the same time you could code as well:
APIzation
JPanel panel = new JPanel();
ImageIcon icon = new ImageIcon("image.jpg");
JLabel label = new JLabel();
label.setIcon(icon);
panel.add(label);
package com.stackoverflow.api;
import javax.swing.*;
public class Human5287521 {
public static JPanel addImageToJPanel(String str1, JPanel panel) {
ImageIcon icon = new ImageIcon(str1);
JLabel label = new JLabel();
label.setIcon(icon);
panel.add(label);
return panel;
}
}
package com.stackoverflow.api;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* how to put Image on JPanel using Netbeans
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/5287521">https://stackoverflow.com/a/5287521</a>
*/
public class APIzator5287521 {
public static void putImage(String str1) throws Exception {
JPanel panel = new JPanel();
ImageIcon icon = new ImageIcon(str1);
JLabel label = new JLabel();
label.setIcon(icon);
panel.add(label);
}
}