How to create refresh/reload in Jtree / Jtable based file listing?

434 views Asked by At

I read tutorial in File Browser Gui , but if the strucutre folder changed, program cannot dynamic reload, how to create refresh/reload function in File Browser GUI ?
Here my uncomplete code

refreshPath = new JButton("Refresh");
refreshPath.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent ae) {
        ....
     }
});
toolBar.add(refreshPath);
1

There are 1 answers

0
mKorbel On
  • FileIO is low level and hard event for Java and Native OS too

  • there are basically two ways

    a) Watching a Directory for Changes for Java7, discussed here.

    b) use some of custom FileIO Watching (I can't suggest what's is better or not, maybe FileWatcher by Apache)

  • in both cases nothing will be notified Swing GUI, have to notify by using SwingWorker or Runnable#Thread

  • by using Runnable#Thread ins't there guarantee that output will be notifyied Event Dispatch Thread, have wrapping output to the Swing GUI to the invokeLater()

  • SwingWorker guarantee that, but for safer output you can to use invokeLater() too, we talking about 4th. short codelines moreover