Java – Sudoku GUI using java

javasolversudokuswinguser interface

I'm currently working on my GUI for this Sudoku solver I'm making. I've managed to print out the board with no problems. However I'd like to know how I would go about to differentiate the 3×3 regions with some kind of thicker or coloured line.

Basically something resembling the picture below.

sudoku

Below is the code I've already implemented. Thanks!

    Board = new JPanel(new GridLayout(9, 9));
    for(int i= 0; i < 9; i++) {

        for(int j = 0; j < 9; j++) {

            board[i][j] = new JLabel();

            board[i][j].setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));


            Font font = new Font("Arial", Font.PLAIN, 20);

            board[i][j].setFont(font);

            board[i][j].setForeground(Color.WHITE);

            board[i][j].setBackground(Color.WHITE);


            board[i][j].setOpaque(true);

            board[i][j].setHorizontalAlignment(JTextField.CENTER);

            Board.add(board[i][j]);

        }
    }

Best Answer

By far the easiest way would be to use nine 3x3 JPanels of JLabels nested into one large 3x3 JPanel of JPanels. Then you could just apply special borders to the small 3x3s.