-1

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). 2) Provide ASCII art or a simple drawing of the layout of the GUI at minimum size, and if resizable, with more width and height. – Andrew Thompson May 24 '15 at 13:50
  • I added everything because I might forget details about the program itself. I'm still thinking for a solution now. – JeobMallari May 24 '15 at 14:02
  • *"I added everything.."* There is more to MCVE than Minimal. That pair of uncompilable code snippets is not a CVE (or an SCCE) of a run-time problem. Please visit the SSCCE link and read it fully. – Andrew Thompson May 24 '15 at 14:05
  • Got it. Will use it next time I ask a question. Thank you sir. – JeobMallari May 24 '15 at 14:16
  • *"Will use it next time I ask a question."* Will not vote to close next time you ask a question. Might also give the problem a close look. Of course, you can [edit *this* question](http://stackoverflow.com/posts/30424253/edit) any time you like.. – Andrew Thompson May 24 '15 at 14:20
  • See also [`JDigit`](http://stackoverflow.com/a/4151403/230513). – trashgod May 24 '15 at 14:42

1 Answers1

0

If this is all you'll get a NullPointerException which you should be able to see at the console. You did not initialize numOfPuzzle but you use it as index in setComponents.

Christian Frommeyer
  • 1,390
  • 1
  • 12
  • 20