I'll give you an example of what a multi-threaded bar would be like so that after the bar is displayed, keep working while the data is modified. You will have to make some adaptations.
class BarraDeProgreso extends JDialog{
private Thread hilo;
private JProgressBar barra;
private int totalDeLaBarra = 2000;
private int velocidad = 1;
BarraDeProgreso() {
this.hilo = new Thread(this::contador);
barra = new JProgressBar(0,totalDeLaBarra);
barra.setValue(0);
this.add(barra);
this.setLayout(new FlowLayout());
this.setLocationRelativeTo(null);
this.setSize(new Dimension(200, 300));
this.setModal(true);
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
@Override
public void setVisible(boolean b) {
hilo.start();
super.setVisible(b);
}
public void contador(){
int contador = 0;
while (contador<=totalDeLaBarra+1) {
try {
barra.setValue(contador);
hilo.sleep(velocidad);
contador++;
} catch (InterruptedException ex) {
Logger.getLogger(BarraDeProgreso.class.getName()).log(Level.SEVERE, null, ex);
}
}
JOptionPane.showMessageDialog(null, "Se va a cerrar la barra!");
dispose();
}
}
public class NewClass {
public static void main(String[] args) {
JFrame frame1 = new JFrame();
frame1.setSize(new Dimension(400, 300));
frame1.setLocationRelativeTo(null);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setLayout(new FlowLayout());
JButton boton = new JButton("Frame2");
frame1.add(boton);
boton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
BarraDeProgreso barra = new BarraDeProgreso();
barra.setVisible(true);
}
});
frame1.setVisible(true);
}
}