Reputation: 7228
I have a JTree which shows content of specific directory. When a download some file with ftp to this directory i want to let my JTree know about it and refresh his contents. How can i refresh JTree after some file added or removed from directory which is root for JTree?
btnRefreshContents.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tree.getModel().
}
});
Upvotes: 0
Views: 1049
Reputation: 21223
You could add directory listener to the underlying tree model. There are many solutions for that. As already stated above, WatchService
in Java 7 can be useful. But since you are not yet at Java 7 you can try other approaches:
JNotify - java library that allows java application to listen to file system events. Here is a sample (make sure you add dll/so dependency to your path.)
VFS from Apache Commons. Commons VFS provides a single API for accessing various different file systems. DefaultFileMonitor is a good example.
Upvotes: 0
Reputation: 16555
If you're using Java 7, you can use the new WatchService
(FileSystem.newWatchService()
) to detect changes to the filesystem. Here's an article on it.
As to updating the JTree component, take a look at this Stack Overflow page.
Upvotes: 3