0
It sounds silly, but I don’t know why you’re not incrementing the Jprogressbar() of my Java Swing application. Follow code below:
public void executar() {
JFileChooser fc = new JFileChooser("Z:\");
fc.showOpenDialog(this);
File file = fc.getSelectedFile();
v_Caminho.setText(file.getAbsolutePath()); //campo texto simples
new Thread() {
@Override
public void run() {
int fileSize = (int) file.length();
v_Progresso.setMaximum(fileSize); //JProgressBar()
try {
for (int i = 0; i <= fileSize; i++) {
fileSize = (fileSize * 100) / 1024;
v_Progresso.setValue(fileSize);
v_Progresso.setStringPainted(true);
sleep(300);
System.out.println("Restam: " + fileSize + " bytes para o carregamento.");
}
} catch (InterruptedException ex) {
Logger.getLogger(ProgressBar.class.getName()).log(Level.SEVERE, null, ex);
}
}
}.start();
}
It calculates the file size and prints in the "Sout" the rest for loading. I need to make this remaining turn increment in Jprogressbar() and it’s not working. What I’m doing wrong?
You have to use SWINGWORKER, see another answer q uses this solution: https://answall.com/a/119137/164151
– Blastoise Opressor