I'm trying to make a dynamic sudoku gui with java, the thing is that I can't seem to get the textfields in the right panels if someone could help me or maybe suggest a better solution to this I would be greatful. The problem is that I only get the textfields in the last panel(at the button to the right). In all the other panels I dont get any textfields, dont know why :P
class Sudoku extends JPanel{
private JTextField textfields[][];
private JPanel panels[][];
public Sudoku(int height, int weight, int dimension){
super();
panels = new JPanel[dimension][dimension];
textfields = new JTextField[dimension][dimension];
setLayout(new GridLayout());
setForeground(Color.black);
setBackground(Color.white);
for (int i = 0;i <= dimension-1;i++ ) {
for (int j = 0;j <= dimension-1;j++ ) {
textfields[i][j] = new JTextField(1);
textfields[i][j].setBackground(Color.YELLOW);
}
}
for (int i = 0;i <= weight;i++ ) {
for (int j = 0;j <= weight;j++ ) {
panels[i][j] = new JPanel(new GridLayout(weight, weight));
}
}
setLayout(new GridLayout(weight,weight,10,10));
setForeground(Color.BLACK);
for (int i = 0;i <= height-1 ;i++ ) {
for (int j = 0;j <= weight-1 ;j++ ) {
for (int k = 0;k <= height-1 ;k++ ) {
for (int l = 0;l <= weight-1 ;l++ ) {
textfields[l][k].setEditable(false);
panels[i][j].add(textfields[l][k]);
}
}
add(panels[i][j]);
}
}
}
}