1
我想记住用户第一次输入的目录,然后将默认目录设置为先前选择的目录。我想通过存储静态变量路径要做到这一点,并把它传递给JFileChooser的,但它不工作,你能告诉我为什么,请:更改JFileChooser的目录
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;
}
}
+1为OR。这是最简单的解决方案。 –
@Eng。 Fouad,我无法为fileopen.getCurrentDirectory返回String。 –