Swing repaint on call

I’m using Java Swing to show a problem being solved recursively. Every time there is a problem that is solved I’d like to repaint my GUI (Solved after if it passes queenSafe method). However I’m having an issue here.

I understand that the Event handler and graphics is controlled by the same thread so I can’t just tell the thread to sleep. So creating a new thread is best? but not so sure on how to implement it. As of right now I’m trying to use a flag to tell the other thread to repaint. But this seems to give me an infinite loop. Any suggestions?

public void queensProblem(){
    this.guiUpdate();
    boolean solved = solveQueenBlindSearch(0);
    if(!solved){
        JOptionPane.showMessageDialog(gui, "Sorry, but this is not solvable");
    }        
}
boolean solveQueenBlindSearch(int col)
{
    if (col >= cb.queens)
        return true;

    for (int row = 0; row < cb.columns; row++)
    {
        if (queenSafe(row, col))
        {
            cb.board[row][col].piece = new Queen();
            this.flag = true;
            if (solveQueenBlindSearch(col + 1) == true)
                return true;
            cb.board[row][col].piece = null;
        }
    }
    return false;
}
void guiUpdate() {
    new Thread() {
        public void run() {
            while(true){
                if(flag){
                    mainLayout.removeAll();
                    mainLayout.add(searches);
                    JPanel newChessboard = cb.drawChessboard();
                    mainLayout.add(newChessboard);
                    mainLayout.repaint();
                    flag = false;
                }
            }
        }        
   }.run();
}