Ich habe wiedermal ein Problem...
Und zwar habe ich eine JProgressBar die mir den Stand des Kopierens anzeigen soll. Extra Threads soll man ja nicht nutzen.
und in einem ActionListener hab ich dann (auf Knopfdruck)
hier ist auch noch die copyDir:
Das Problem ist das die JProgressBar nicht aktuell ist... d.h. sie wird gar nicht angezeigt.
lg
Und zwar habe ich eine JProgressBar die mir den Stand des Kopierens anzeigen soll. Extra Threads soll man ja nicht nutzen.
Java:
localPBar = new JProgressBar();
localPBar.setStringPainted(true);
localPBar.setMinimum(0);
und in einem ActionListener hab ich dann (auf Knopfdruck)
Java:
localPBar.setMaximum(vItemsToCutCopy.size());
localPBar.setValue(0);
localPBar.setVisible(true);
synchronized (vItemsToCutCopy)
{
for(int i = 0; i < vItemsToCutCopy.size(); i++)
{
Tree t = (Tree)vItemsToCutCopy.get(i);
File fOld = new File(t.getPath());
if(!fOld.exists())
{
localPBar.setMaximum(localPBar.getMaximum()-1);
continue;
}
File fNew = new File(localPath.getText()+t.getName());
if(localIsCut)
{
fOld.renameTo(fNew);
}else{
try
{
if(fOld.isDirectory())
{
copyLocalDirectory(fOld,fNew);
continue;
}
FileChannel inChannel = new FileInputStream(fOld).getChannel();
FileChannel outChannel = new FileOutputStream(fNew).getChannel();
inChannel.transferTo(0, inChannel.size(), outChannel);
localPBar.setValue(localPBar.getValue()+1);
}
catch(FileNotFoundException e1){}
catch(IOException e2){}
}
t = null;
fOld = null;
fNew = null;
}
}
vItemsToCutCopy.removeAllElements();
localPBar.setVisible(false);
localPBar.setValue(0);
hier ist auch noch die copyDir:
Java:
private void copyLocalDirectory(File fOld,File fNew)
{
File[] files = fOld.listFiles();
fNew.mkdirs();
for (File file : files)
{
if (file.isDirectory())
{
copyLocalDirectory(file, new File(fNew.getAbsolutePath() + System.getProperty("file.separator") + file.getName()));
}else{
try
{
FileChannel inChannel = new FileInputStream(file).getChannel();
FileChannel outChannel = new FileOutputStream(fNew.getAbsolutePath() + System.getProperty("file.separator") + file.getName()).getChannel();
inChannel.transferTo(0, inChannel.size(), outChannel);
localPBar.setValue(localPBar.getValue()+1);
}
catch(FileNotFoundException e1){}
catch(IOException e2){}
}
}
files = null;
fOld = null;
fNew = null;
}
Das Problem ist das die JProgressBar nicht aktuell ist... d.h. sie wird gar nicht angezeigt.
lg