Boa tarde pessoal!
Estou fazendo uma rotina simples, onde tenho alguns arquivos em XML e gero um relatorio deles, ou seja, digo qual é a pasta onde contém os arquivos .xml e a rotina vai pegando arquivo por arquivo e criando um relatorio.
Conforme for gerando os relatorios gostaria de um JProgressBar fosse evoluindo e mostrando na tela, porém até evolui mas nao mostra na tela, somente quando completa tudo, ai fica 100%.
Segue me código:
private int iCount = 0;
private int iTotal = 0;
private void jbGerarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (!textarea.getText().equals("")) {
if (!txSalva.getText().equals("")) {
ProgressBar.setMinimum(0);
ProgressBar.setMaximum(textarea.getLineCount() -1);
ProgressBar.setValue(0);
jbGerar.setEnabled(false);
textareaConvertido.setText("");
textareaConvertido.setWrapStyleWord(true);
String sLinha = null;
ConverteXMLDacte convert = new ConverteXMLDacte();
for (int i = 0; textarea.getLineCount() > i; i++) {
int inicio;
try {
inicio = textarea.getLineStartOffset(i);
int fim = textarea.getLineEndOffset(i);
String linha = textarea.getText(inicio, fim - inicio);
sLinha = linha;
int iTipo = 0;
if (!linha.equals("")) {
String sNome = listaNome.get(i);
sNome = sNome.replace(".xml", ".pdf");
textareaConvertido.setText(textareaConvertido.getText() + txSalva.getText() + sNome + "\n");
if (bgItens.getSelection().equals(btn01.getModel())) {
iTipo = 1;
} else if (bgItens.getSelection().equals(btn02.getModel())) {
iTipo = 2;
} else if (bgItens.getSelection().equals(btn03.getModel())) {
iTipo = 3;
}
convert.converte(linha, txSalva.getText(), sNome, iTipo);
iCount = i;
iTotal = textarea.getLineCount() -1;
new Thread(new Tempo()).start();
}
} catch (BadLocationException | MalformedURLException | DocumentException ex) {
Logger.getLogger(GeradorXMl.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, ex.getMessage() + ": " + sLinha);
} catch (FileNotFoundException ex) {
Logger.getLogger(GeradorXMl.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(GeradorXMl.class.getName()).log(Level.SEVERE, null, ex);
}
}
JOptionPane.showMessageDialog(null, "Operação concluída com sucesso!");
} else {
JOptionPane.showMessageDialog(null, "Selecione um caminho para salvar os arquivos PDF. Verifique!");
}
} else {
JOptionPane.showMessageDialog(null, "Nenhum arquivo existente para esse caminho. Verifique!");
}
jbGerar.setEnabled(true);
}
private class Tempo implements Runnable {
@Override
public void run() {
ProgressBar.setValue(iCount + 1);
jlTotal.setText(iCount + 1 + " de " + iTotal);
ProgressBar.repaint();
jlTotal.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(GeradorXMl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Obrigado!