I have a JLabel
array but when an image is attached to it and added to my container it doesn't appear on the JFrame
, unlike the non-array JLabel
s.
I've attempted changing Opaque settings of the image it overlays, setting it to visible, and changing the layout of the image.
I'm new to Stack Overflow and relatively new to Swing so all criticism is welcome.
import java.awt.Container;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Connect_Four extends JFrame {
private static final long serialVersionUID = 1L;
static JLabel[] piecelabel;
static int piececounter;
public Connect_Four(String title) {
piececounter = 0;
Container c = getContentPane();
piecelabel = createLabels();
piecelabel[piececounter].setIcon(new ImageIcon("F:/redpiece.jpg"));
piecelabel[piececounter].setBounds(0, (750 - (counter[0] * 100)), 135, 100);
c.add(piecelabel[piececounter]);
}
public JLabel[] createLabels() {
JLabel[] labels = new JLabel[42]; //used for connect 4 pieces
for (int i = 0; i < 42; i++) {
labels[i] = new JLabel();
}
return labels;
}
}