我正在尝试创建一个“保存到”文件选择器。但是当我执行代码并点击“打开”时,会打开一个新的filechooser窗口。代码:
int val = jFileChooser1.showOpenDialog(null);
private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(evt.getActionCommand());
int val = jFileChooser1.showOpenDialog(null);
if(val == jFileChooser1.APPROVE_OPTION){
File filePath = jFileChooser1.getSelectedFile();
directoryPath = filePath.toString();
System.out.println("Directory Path: " + directoryPath);
}else{
System.exit(0);
}
}
答案 0 :(得分:3)
尝试showSaveDialog方法。
答案 1 :(得分:2)
int val = jFileChooser1.showOpenDialog(parent);