I want to remember the directory what user entered first time and then set the default directory to previously chosen directory. I am trying to do this by storing a static variable as path and pass it to JFileChooser, but its not working can you tell me why , please:
public class BrowseInputUI {
public static String Path="";
public BrowseInputUI() {
JFileChooser fileopen = new JFileChooser(Path);//on second time user should see previous path
int ret = fileopen.showDialog(null, "Provide a file");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
Path=file.getPath();
}
else if (ret == JFileChooser.CANCEL_OPTION){
Path=null;
}
}
public String GetPath(){
return Path;
}
}
Try
fileopen.getCurrentDirectory()instead offile.getPath(). OR just make your filechooser as a class field: