下面列出了javax.swing.JFileChooser#isDirectorySelectionEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String fileNameString(File file) {
if (file == null) {
return null;
} else {
JFileChooser fc = getFileChooser();
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
return file.getPath();
} else {
return file.getName();
}
}
}
private void doSelectedFileChanged(PropertyChangeEvent e) {
File f = (File) e.getNewValue();
JFileChooser fc = getFileChooser();
if (f != null
&& (fc.isFileSelectionEnabled() && !f.isDirectory() || f.isDirectory() && fc.isDirectorySelectionEnabled())) {
setFileName(fileNameString(f));
setFileSelected();
}
}
private void doSelectedFilesChanged(PropertyChangeEvent e) {
File[] files = (File[]) e.getNewValue();
JFileChooser fc = getFileChooser();
if (files != null && files.length > 0
&& (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) {
setFileName(fileNameString(files));
} else {
setFileName("");
}
setFileSelected();
}
private void doDirectoryChanged(PropertyChangeEvent e) {
JFileChooser fc = getFileChooser();
FileSystemView fsv = fc.getFileSystemView();
clearIconCache();
File currentDirectory = fc.getCurrentDirectory();
this.fileList.updatePath(currentDirectory);
if (currentDirectory != null) {
this.directoryComboBoxModel.addItem(currentDirectory);
getNewFolderAction().setEnabled(currentDirectory.canWrite());
getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
getGoHomeAction().setEnabled(!userHomeDirectory.equals(currentDirectory));
if (fc.isDirectorySelectionEnabled()) {
if (fc.isFileSelectionEnabled()) {
setFileName(null);
} else {
if (fsv.isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
}
}
setFileSelected();
}
}
}
private void doFileSelectionModeChanged(PropertyChangeEvent e) {
doFilterChanged(e);
JFileChooser fc = getFileChooser();
File currentDirectory = fc.getCurrentDirectory();
if (currentDirectory != null && fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()
&& fc.getFileSystemView().isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
}
setFileSelected();
}