Bom dia, estou com problemas no uso do SwingUtilities.invokeLate
Gostaria de entender porque meu código não atualiza o JTextArea sendo que eu usei o SwingUtilities.invokeLater:
public class raRecebimentoImg extends JPanel{
private static final long serialVersionUID = 8521663699492798052L;
private static Logger logger = LogManager.getLogger();
private final String DIRETORIO_ORIGEM = "C:\\origem\\";
private final String DIRETORIO_BACKUP = "C:\\Imagens";
private final String DIRETORIO_DESTINO_fx1 = "C:\\Origem1";
private final String DIRETORIO_DESTINO_ = "C:\\Origem2";
private final String DIRETORIO_DESTINO_DESPADRONIZADO = "C:\\Origem3";
private JTextField txtEst;
private JTextField txtfx1Fx1;
private final JTextArea txtrStatus = new JTextArea();
private JScrollPane textAreaPane = new JScrollPane(txtrStatus);
public raRecebimentoImg(final JInternalFrame frameRecebimentoImgs) {
setLayout(new MigLayout("", "[grow]", "[][grow][grow][][][][]"));
logger.info("----- Iniciando: Recebimento de Imagens de ra da origem -----");
JLabel lblRecebimentoImgs = new JLabel("Recebimento de Imagens de ra da origem");
lblRecebimentoImgs.setFont(new Font("Tahoma", Font.BOLD, 14));
add(lblRecebimentoImgs, "cell 0 0,alignx center,aligny center");
DefaultMutableTreeNode root = new DefaultMutableTreeNode("origem");
File pastaRaiz = new File(DIRETORIO_ORIGEM);
File[] arquivosDiretorioOrigem = pastaRaiz.listFiles();
//Listando pastas na origem para criar o DefaultMutableTreeNode
logger.info("Listagem das pastas na Raiz:");
for (File arquivoDiretorioOrigem : arquivosDiretorioOrigem) {
logger.info(arquivoDiretorioOrigem + " é um " + (arquivoDiretorioOrigem.isDirectory() ? "diretório" : "arquivo"));
if(arquivoDiretorioOrigem.isDirectory()){
DefaultMutableTreeNode pastasDentroDiretorioOrigem = new DefaultMutableTreeNode(arquivoDiretorioOrigem.toString().replace(DIRETORIO_ORIGEM, ""));
File subPastaRaiz = new File(arquivoDiretorioOrigem.toString());
File[] arquivosSubPastaRaiz = subPastaRaiz.listFiles();
for (File subPasta : arquivosSubPastaRaiz) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(subPasta.toString().substring(subPasta.toString().lastIndexOf("\\")+1));
pastasDentroDiretorioOrigem.add(node);
}
root.add(pastasDentroDiretorioOrigem);
}
}
final JTree tree = new JTree(root);
tree.setVisibleRowCount(15);
tree.setEditable(false);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
JScrollPane treeView = new JScrollPane(tree);
add(treeView, "cell 0 1,grow");
txtrStatus.setRows(5);
add(textAreaPane, "cell 0 2,grow");
JLabel lblPadraofx1 = new JLabel("Padr\u00E3o fx1");
lblPadraofx1.setFont(new Font("Tahoma", Font.PLAIN, 13));
add(lblPadraofx1, "flowx,cell 0 3");
JLabel lblPadrao = new JLabel("Padr\u00E3o Est\u00E1tico ");
lblPadrao.setFont(new Font("Tahoma", Font.PLAIN, 13));
add(lblPadrao, "flowx,cell 0 4");
JButton btnTransferir = new JButton("Transferir");
btnTransferir.setFont(new Font("Tahoma", Font.PLAIN, 13));
add(btnTransferir, "cell 0 5,alignx center,aligny center");
btnTransferir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final TreePath[] paths = tree.getSelectionPaths();
if(paths == null || paths.length == 0){
JOptionPane.showMessageDialog(null, "Por favor, selecione uma pasta!", "Aviso", JOptionPane.WARNING_MESSAGE);
}
else{
for (final TreePath path : paths) {
if(path.getParentPath() != null && path.getParentPath().getPathCount() == 1){
if(JOptionPane.showConfirmDialog(null, "Confirmar a cópia da pasta:\n " + DIRETORIO_ORIGEM + path.getLastPathComponent() + "?", "Confirmar", JOptionPane.YES_NO_OPTION) == 0){
logger.info("Início da cópia dos arquivos");
copiarorigemParaBackup(path);
logger.info("Fim da cópia dos arquivos");
JOptionPane.showMessageDialog(null, "Fim da cópia dos arquivos");
}
}
else{
logger.info("Por favor, selecione uma pasta válida");
JOptionPane.showMessageDialog(null, "Por favor, selecione uma pasta válida!", "Aviso", JOptionPane.WARNING_MESSAGE);
}
}
}
}
private void copiarorigemParaBackup(final TreePath path) {
logger.info("copiarorigemParaBackup(); path=" + path.toString());
//Backup das imagens
Path source = Paths.get(DIRETORIO_ORIGEM + path.getLastPathComponent());
Path target = Paths.get(DIRETORIO_BACKUP + "\\" + path.getLastPathComponent());
//Copia para a pasta de backup
logger.info("Copiando dê: " + source.toString());
logger.info("Criando Backup em: " + target.toString());
copiar(source, target);
//Copia das imagens paras as pastas fx1, e despadronizado
File pasta = new File(source.toString());
File[] arquivosDiretorioOrigem = pasta.listFiles();
String subPasta = "";
String fx1[] = txtfx1Fx1.getText().split(",");
String [] =txtEst.getText().split(",");
int rafx1 = 0;
int ra = 0;
logger.info("Iniciando cópia para as pastas fx1 e Estático");
logger.info("Padrões informados no campo fx1: " + txtfx1Fx1.getText());
logger.info("Padrões informados no campo Estático: " + txtEst.getText());
for (final File file : arquivosDiretorioOrigem) {
subPasta = file.toString().substring(file.toString().lastIndexOf("\\")+1, file.toString().length()).toLowerCase();
source = Paths.get(file.toString());
for(int i=0; i < fx1.length; i++){
rafx1 = StringUtils.countMatches(subPasta, fx1[i].trim());
if(rafx1 > 0){
target = Paths.get(DIRETORIO_DESTINO_fx1 + "\\" + subPasta);
break;
}
}
for(int i=0; i < .length; i++){
ra = StringUtils.countMatches(subPasta, [i].trim());
if(ra > 0){
target = Paths.get(DIRETORIO_DESTINO_ + "\\" + subPasta);
break;
}
}
if((rafx1 == 0 && ra == 0) || (rafx1 > 0 && ra > 0)){
target = Paths.get(DIRETORIO_DESTINO_DESPADRONIZADO + "\\" + subPasta);
}
//Copia para as pastas fx1 e
logger.info("Copiando: " + target.toString());
copiar(source, target);
}
}
private void copiar(Path source, final Path target) {
SwingUtilities.invokeLater(new Runnable()
{
public void run(){
txtrStatus.append(target.toString() + "\n");
}
});
try {
Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new CopyDirectory(source, target ));
} catch (FileAlreadyExistsException e) {
logger.error("Arquivo já existe", e);
JOptionPane.showMessageDialog(null, "Arquivo já existe: " + e.getMessage() + "\n Na pasta destino: " + target, "ERRO", JOptionPane.ERROR_MESSAGE);
} catch (DirectoryNotEmptyException e) {
logger.error("Diretório não está vazio", e);
JOptionPane.showMessageDialog(null, e.getMessage() + "\n Na pasta destino: " + target, "ERRO", JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
logger.error("Erro de I/O", e);
} catch (Exception e) {
logger.error("Exception", e);
}
}
});
txtEst = new JTextField();
lblPadrao.setLabelFor(txtEst);
txtEst.setText(", estático, est, bprv, portatil, batalhao, batalhão");
add(txtEst, "cell 0 4,growx,aligny center");
txtEst.setColumns(50);
Component horizontalStrut = Box.createHorizontalStrut(20);
add(horizontalStrut, "cell 0 3");
txtfx1Fx1 = new JTextField();
lblPadraofx1.setLabelFor(txtfx1Fx1);
txtfx1Fx1.setText("fx1, fx, 1");
add(txtfx1Fx1, "cell 0 3,growx,aligny center");
txtfx1Fx1.setColumns(50);
}
}
Desde já agradeço!