I'm making a Chess-like game in Java Swing (I know Swing isn't the proper way to go about it but I want to attempt it nevertheless) I am having a problem with making the chess pieces show up on the display at the proper paces. Due to the nature of the chess pieces physical positions, I cannot use a layout manager. The code looks something like this (it's admittedly awkwardly designed) :
public class Window extends JFrame {
private JPanel board;
public Window() {
super();
board = new JPanel();
JLabelOrganizer jlo = new JLabelOrganizer();
for (JLabel: JLabelOrganizer) {
JLabel.setBounds(calcX(), calcY(), width, height);
board.add(JLabel);
}
board.setBounds(x, y, width1, height1);
board.setLayout(null);
add(board);
setLayout(null);
}
public class JLabelOrganizer {
public JLabelOrganizer {
instantiate Type1 and Type2 JLabel objects and store them
}
public class Type1 extends JLabel {
}
public class Type2 extends JLabel {
}
}
}
The classes Type1 and Type2 represent the pieces. When this runs, the JLabels (Type1 and Type2) do not show up at the correct place as designated from setBounds(). However, the board JPanel holding these pieces is set up at the correct place as designated from the call of its own setBounds(). Does anything have an idea as to why this is happening? Could it be because I'm inheriting from JLabel or the JLabel classes are inner classes? Thanks.
Edit: Forgot to specify that the JLabels only show up in the upper left hand corner of where the JPanel is located no matter what x and y positions I set them to.