It was working before I added the 3D array of textfields, then nothing showed from all I have created. After removing them, still nothing shows up. How do I add a 3D array of JTextFields without ruining the whole layout?
I initialized them first:
int numOfPuzzles;
int puzzleSize;
JTabbedPane tabbedPane;
JPanel[] southPanel;
JPanel[] centerPanel;
JPanel[] sudokuPanel;
JPanel[] buttonsPanel;
JButton[] nextButton;
JButton[] prevButton;
ArrayList<int[][]> sudoku;
JTextField[][][] textFields;
public SudokuSolverUI(ArrayList<int[][]> sudoku){
this.sudoku = sudoku;
this.numOfPuzzles = numOfPuzzles;
this.puzzleSize = puzzleSize;
this.setTitle("Sudoku XY");
this.setVisible(true);
this.setSize(900, 700);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setComponents();
}
then at public void setComponents
I instantiated the necessary components, added them to the panel, then:
public void setComponents(){
this.tabbedPane = new JTabbedPane();
centerPanel = new JPanel[this.numOfPuzzles];
sudokuPanel = new JPanel[this.numOfPuzzles];
buttonsPanel = new JPanel[this.numOfPuzzles];
southPanel = new JPanel[this.numOfPuzzles];
nextButton = new JButton[this.numOfPuzzles];
prevButton = new JButton[this.numOfPuzzles];
for(int i=0;i<this.numOfPuzzles;i++){
nextButton[i] = new JButton("Next");
nextButton[i].addActionListener(this);
prevButton[i] = new JButton("Prev");
prevButton[i].addActionListener(this);
centerPanel[i] = new JPanel();
sudokuPanel[i] = new JPanel();
buttonsPanel[i] = new JPanel();
southPanel[i] = new JPanel();
for(int j=0;j<this.sudoku.get(i).length;j++){
for(int k=0;k<this.sudoku.get(i).length;k++){
textFields[i][j][k] tf = new JTextField();
sudokuPanel[i].add(tf);
}
}
southPanel[i].setLayout(new FlowLayout());
southPanel[i].add(prevButton[i]);
southPanel[i].add(nextButton[i]);
centerPanel[i].setLayout(new BorderLayout());
centerPanel[i].add(southPanel[i], BorderLayout.SOUTH);
centerPanel[i].add(sudokuPanel[i], BorderLayout.CENTER);
centerPanel[i].add(buttonsPanel[i], BorderLayout.EAST);
centerPanel[i].setVisible(true);
centerPanel[i].validate();
tabbedPane.addTab("Puzzle #"+(i+1), centerPanel[i]);
this.getContentPane().add(tabbedPane);
}
}
nothing shows up. Please help.