Hello, I'm trying to add an icon to a JPanel in the event where a button is pressed. I have the following code:
-
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
-
javax.swing.ImageIcon icon = new javax.swing.ImageIcon("/home/bbraun/NetBeansProjects/RPGI/sample2.jpg");
-
javax.swing.JLabel label = new javax.swing.JLabel();
-
label.setIcon(icon);
-
jPanel1.add(label);
-
}
-
I specify an absolute path where the image exists, but it won't display. With simpler examples I was able to get this to work. jPanel1 is nested in a JTabbedPane. Even if I change icon and label to member variables of the class it doesn't work. The JPanel shows up fine, but it has nothing inside.