I am using java 7 Files.walkFileTree method to traverse through whole disk. I am trying to update the javafx label and progress bar in the UI class I have created, from the visitFile() method of my custom FileVisitor. In the javafx UI class I create the task and start it. I did some research and someone suggested I implement FileVisitor and extend task so that I can updateMessage() from visitFile() but I tried that and it does not work. Javafx UI class :
FileSystemTraverse task = new FileSystemTraverse(client);
// here i create label and bind it to the task
final Thread thread = new Thread(task);
thread.start();
FileSystemTraverse class :
public class FileSystemTraverse extends Task implements FileVisitor<Path>
{
// The usual implemented methods, constructor and so on ...
public FileVisitResult visitFile(Path filePath, BasicFileAttributes attributes) throws IOException {
Objects.requireNonNull(attributes);
Objects.requireNonNull(filePath);
if (attributes.isRegularFile()) {
// Here I do some operations and if I found the file i need
// I update the message (this is just an example)
updateMessage(filePath.toString);
}
return FileVisitResult.CONTINUE;
}
@Override
protected Object call() throws Exception {
Path path = Paths.get("D:\\");
// This one below gets updated in the UI.
updateMessage("asdkjasdkjhakj");
FileSystemTraverse printFiles = new FileSystemTraverse(client);
Files.walkFileTree(path,printFiles);
return null;
}
}
So my question is - is there really a way of doing this ? I read somewhere here about doing this with swing (they use publish) but with javafx it does not seem to work.
Thank you in advance.