I'm trying to make a game of chess, but when I try to insert chess pieces through JLabel icons, they cover the actual chessboard, thus only having the pieces left on screen. How do I make the JLabels not cover up paintings behind it? I'm doing this using a class that extends JApplet.
UPDATE: it worked by using Applet instead of JApplet, though I still have no idea why.
This is the code:
ChessBoard board; // done in another class file
public static int CEL_WIDTH = 65;
public static int MARGIN_X = 50, MARGIN_Y = 50;
imagePos = "../src/Schack/Bilder/";
JLabel label;
public void init() {
setLayout(null);
this.setSize(600, 600);
board = new ChessBoard(MARGIN_X, MARGIN_Y, CEL_WIDTH);
ImageIcon imageIcon = new ImageIcon(getImage(getDocumentBase(), imagePos + "blackRook.png")); //scaling my image
Image image = imageIcon.getImage();
Image newimg = image.getScaledInstance(CEL_WIDTH, CEL_WIDTH, java.awt.Image.SCALE_SMOOTH);
imageIcon = new ImageIcon(newimg);
label = new JLabel(imageIcon);
label.setBounds(MARGIN_X, MARGIN_Y, CEL_WIDTH, CEL_WIDTH);
add(label);
}
@Override
public void paint(Graphics g) {
board.paintChessBoard(g); // another paint method in a different class file
super.paint(g);
}