下面列出了javax.swing.JFileChooser#setVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Optional<String> saveAsFile() {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Save as ");
//按默认方式显示
chooser.showSaveDialog(null);
chooser.setVisible(true);
//得到用户希望把文件保存到何处
File file = chooser.getSelectedFile();
if (Objects.isNull(file)) {
log.warn("please select file: chooser={}", chooser);
return Optional.empty();
}
//准备写入到指定目录下
String path = file.getAbsolutePath();
try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) {
bw.write(Note.textArea.getText());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return Optional.of(path);
}
/**
* Opens the file chooser for loading the current configuration file.
*/
public void load() {
JFileChooser fc = fileChooser.get();
fc.setFileFilter(null);
fc.setVisible(true);
fc.setCurrentDirectory(getFile());
int returnVal = fc.showDialog(null, "Load");
if (returnVal == JFileChooser.APPROVE_OPTION) {
load(fc.getSelectedFile());
}
}
/**
* Opens the file chooser for saving the current configuration file.
*/
public void saveAs() {
JFileChooser fc = fileChooser.get();
fc.setFileFilter(null);
fc.setVisible(true);
fc.setCurrentDirectory(getFile());
int returnVal = fc.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
save(fc.getSelectedFile());
}
}
private void outputFormatComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputFormatComboBoxItemStateChanged
if (((String) outputFormatComboBox.getSelectedItem()).equals("PropertyList to Keel") || ((String) outputFormatComboBox.getSelectedItem()).equals("Weka to Keel") || ((String) outputFormatComboBox.getSelectedItem()).equals("Keel to Keel")) {
optionsButton.setEnabled(false);
} else {
optionsButton.setEnabled(true);
}
if (((String) outputFormatComboBox.getSelectedItem()).equals("CSV to Keel") || ((String) outputFormatComboBox.getSelectedItem()).equals("TXT to Keel") || ((String) outputFormatComboBox.getSelectedItem()).equals("PRN to Keel") || ((String) outputFormatComboBox.getSelectedItem()).equals("Excel to Keel") || ((String) outputFormatComboBox.getSelectedItem()).equals("HTML Tab to Keel")) {
processHeaderCheckBox.setEnabled(true);
} else {
processHeaderCheckBox.setEnabled(false);
}
setExtensionAndDescription();
JFileChooser chooser = fileBrowserPanel.getFileChooser();
chooser.resetChoosableFileFilters();
if (ext.equals("DISABLE")) {
chooser.setFileFilter(null);
chooser.setVisible(false);
} else {
KeelFileFilter fileFilter = new KeelFileFilter();
fileFilter.addExtension(ext);
fileFilter.setFilterName(desc);
chooser.setFileFilter(fileFilter);
chooser.setVisible(true);
//fileBrowserPanel.repaint();
}
importOptionsDialog = createNewOptionsDialog(((String) outputFormatComboBox.getSelectedItem()));
}