I need to have a complete list of all the files over UNC path. Files are listing very slow using java.io.File.listFiles()
method. My Application is also getting stuck when it trying to get file icon using FileSystemView.getSystemIcon
to render it into JTable
. When I comment the particular code under run
method it does not get stuck. How to get rid of this issue?
import java.io.File;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.filechooser.FileSystemView;
/**
*
* @author admin
*/
public class MySwingWorker implements Runnable {
private JLabel label;
private String strFile;
private Icon icon;
public MySwingWorker(String strFile, JLabel label) {
this.strFile = strFile;
this.label = label;
}
@Override
public void run() {
File f = new File(strFile);
try {
FileSystemView fw = FileSystemView.getFileSystemView();
if (f.exists() == true) {
icon = fw.getSystemIcon(f);
} else {
File fTemp = new File(System.getProperty("pro.temp.home"), "Temp");
if (fTemp.exists() == false) {
try {
fTemp.mkdirs();
} catch (Exception ex) {
//ignored
}
}
//Replaced "Temp" with fTemp
File fNewFile = new File(fTemp, f.getName());
if (fNewFile.createNewFile()) {
icon = fw.getSystemIcon(fNewFile);
}
}
} catch (Exception e) {
}
label.setIcon(icon);
}
}