我有下面的代碼:JFileChooser中選擇豬病
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnNajitPDFCache) {
JFileChooser chooser;
String choosertitle = "Select directory.";
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonText("OK");
//
// disable the "All files" option.
//
chooser.setAcceptAllFileFilterUsed(false);
//
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
textFieldPDFCache.setText(chooser.getCurrentDirectory()+"");
}
}
}
這是確定的。我選擇打開選擇器窗體中的c:\ test文件夾,然後點擊按鈕確定。
但是chooser.getCurrentDirectory()
只返回c:\。爲什麼?哪裏不對?