textArea
と呼ばれるこのJTextArea
を更新しようとしていますが、これらの写真をコピーしている間に更新しても動作するようには思えません。JTextAreaのリアルタイム更新が必要です
String name = "";
int numberOfPicturesCopied = 0;
while (pictures.isEmpty() == f) {
try {
File tmp = pictures.firstElement();
name = tmp.getName();
String filename = destination + Meta.date(tmp) + tmp.getName();
Path source = tmp.toPath();
File destFile = new File(filename);
Path destination = destFile.toPath();
Files.copy(source, destination,
StandardCopyOption.COPY_ATTRIBUTES);
textArea.append("Copied " + name + "\n");
pictures.removeElementAt(0);
numberOfPicturesCopied++;
} catch (FileAlreadyExistsException faee) {
textArea.append("Skipped " + name
+ ": Picture Already In Computer\n");
} catch (NoSuchFileException ncfe) {
File tmp = pictures.firstElement();
String filename = destination + Meta.date(tmp);
File newDir = new File(filename);
newDir.mkdir();
} catch (IOException ee) {
// TODO Auto-generated catch block
ee.printStackTrace();
}
}
をして、私はこれにそれを変更:私はこのコードを使用していたのと同じ結果に
public void copyPictures(){
SwingUtilities.invokeLater(new Thread(){
public void run(){
String name = "";
while(pictures.isEmpty() == f){
try {
File tmp = pictures.firstElement();
name = tmp.getName();
String filename = destination + Meta.date(tmp) + tmp.getName();
Path source = tmp.toPath();
File destFile = new File(filename);
Path destination = destFile.toPath();
Files.copy(source, destination, StandardCopyOption.COPY_ATTRIBUTES);
textArea.append("Copied " + name + "\n");
pictures.removeElementAt(0);
numberOfPicturesCopied++;
} catch(FileAlreadyExistsException faee){
textArea.append("Skipped " + name +": Picture Already In Computer\n");
} catch (NoSuchFileException ncfe){
File tmp = pictures.firstElement();
String filename = destination + Meta.date(tmp);
File newDir = new File(filename);
newDir.mkdir();
} catch (IOException ee) {
// TODO Auto-generated catch block
ee.printStackTrace();
}
}
}
});
}
。助言がありますか?
また、テキスト領域の上部にテキストを入力する方法はありますか?あなたが求めているもの
1)すぐに役立つようにするには、[SSCCE]( http://sscce.org/)を試してみてください。試したことの他のものは、(例えば) 'copyPictures2()'メソッドのように指定することができます。 2)あなたがEDTをブロックしているようです。 'SwingWorker'を使います。 –
'SwingUtilities.invokeLater(new Thread())'が間違っています。バックグラウンドスレッドで実行したいファイルI/O作業を、EDTで実行するSwingコンポーネントの更新から完全に分離する必要があります。 – wolfcastle