swing的目录选择问题
来源:百度知道 编辑:UC知道 时间:2024/05/04 10:19:38
我想问的是在swing中有没有一个方法,当我按了“浏览按钮”后,弹出一个路径选择器。在这里只要选择路径,而不是具体打开或选择某个文件。因为这个目录是我做文件保存的目录。并且要把这个目录的路径记录下来。
谢谢!
//is this?
import java.io.File;
import javax.swing.JFileChooser;
public class FileWindow extends JFileChooser {
private static final long serialVersionUID = 1L;
private String defaultSavepath = "F:/JtestFile";
public FileWindow() {
}
public File load() {
File file = null;
this.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal;
returnVal = this.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = this.getSelectedFile();
}
return file;
}
public File save() {
File file = null;
file = new File(this.getDefaultSavepath());
if (!file.exists()) {
file.mkdir();
}
this.setFileSelectionMode(JFileChooser.FILES_ONLY);
this.setCurrentDirectory(file);
this.showSaveDialog(null);
file = this.getSelectedFile();
retu