I have a problem that I cannot detect what is happening when placing some Jlabels with images inside a JFrame, I have managed to place them "Correctly", with the exception of always the last label, it places it in a position of X and And, which doesn't make sense, I leave you the necessary code and an image of what it does to me. I hope someone can help me I've been with this problem for hours without being able to solve it, thanks in advance.
This is the code of the JFrame class with the labels:
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Tablero extends JFrame{
private Inicio origen;
public Tablero() {
this.setSize(816, 710);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
for (int i = 0; i < 6; i++) {
JLabel p=new JLabel();
p.setIcon(new ImageIcon("src\\tablero\\"+i+".png"));
p.setBounds(136*i, 554, 136, 136);
this.add(p);
}
}
P.S. From this class I create the object and display it through another JFrame that is simple to start. The images contained in the labels have numerical names to facilitate access to them.
By default a JFrame has a BorderLayout as LayoutManager , and by default it places the centered components .
To avoid problems like you have, it is best to override that LayoutManager with setLayout();
Now it should work for you.