下面列出了javax.swing.JFileChooser#isMultiSelectionEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean marathon_select(String value) {
JFileChooser fc = (JFileChooser) component;
if (value.equals("")) {
fc.cancelSelection();
return true;
}
if (fc.isMultiSelectionEnabled()) {
fc.setSelectedFiles(ChooserHelper.decode(value));
fc.approveSelection();
return true;
}
fc.setSelectedFile(ChooserHelper.decodeFile(value));
fc.approveSelection();
return true;
}
private void recordApproveSelection(JFileChooser fc) {
if (fc.isMultiSelectionEnabled()) {
File[] fs = fc.getSelectedFiles();
recorder.recordSelect(this, ChooserHelper.encode(fs));
} else {
File file = fc.getSelectedFile();
recorder.recordSelect(this, ChooserHelper.encode(file));
}
}
@Override
public void loggedActionPerformed(ActionEvent e) {
if (UIManager.getBoolean("FileChooser.readOnly")) {
return;
}
JFileChooser fc = getFileChooser();
File currentDirectory = fc.getCurrentDirectory();
FileSystemView fsv = fc.getFileSystemView();
File newFolder = null;
String name = SwingTools.showInputDialog("file_chooser.new_folder", "");
// abort if cancelled or user entered nothing
if (name == null || name.isEmpty()) {
return;
}
try {
newFolder = fsv.createNewFolder(currentDirectory);
if (newFolder.renameTo(fsv.createFileObject(fsv.getParentDirectory(newFolder), name))) {
newFolder = fsv.createFileObject(fsv.getParentDirectory(newFolder), name);
} else {
SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.rename", name);
}
} catch (IOException exc) {
SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.create", name);
return;
} catch (Exception exp) {
// do nothing
}
if (fc.isMultiSelectionEnabled()) {
fc.setSelectedFiles(new File[] { newFolder });
} else {
fc.setSelectedFile(newFolder);
}
fc.rescanCurrentDirectory();
}
public static File[] showOpenFolderDialog( final Component parent, final String title, final boolean multiselection,
final File initialPath ) {
RunnableWithParameters runnable = new RunnableWithParameters(){
public void run() {
JFileChooser fc = new JFileChooser();
fc.setDialogTitle(title);
fc.setDialogType(JFileChooser.OPEN_DIALOG);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setMultiSelectionEnabled(multiselection);
fc.setCurrentDirectory(initialPath);
fc.setFileHidingEnabled(false);
int r = fc.showOpenDialog(parent);
if (r != JFileChooser.APPROVE_OPTION) {
this.returnValue = null;
return;
}
if (fc.isMultiSelectionEnabled()) {
File[] selectedFiles = fc.getSelectedFiles();
this.returnValue = selectedFiles;
} else {
File selectedFile = fc.getSelectedFile();
if (selectedFile != null && selectedFile.exists())
PreferencesHandler.setLastPath(selectedFile.getAbsolutePath());
this.returnValue = new File[]{selectedFile};
}
}
};
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (Exception e) {
Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
}
}
return (File[]) runnable.getReturnValue();
}
void grab(JFileChooser jfc) {
location = jfc.getLocation();
if(jfc.isMultiSelectionEnabled())
selection = jfc.getSelectedFiles();
else
selection = new File[] {jfc.getSelectedFile()};
}
private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
// TODO add your handling code here:
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setAcceptAllFileFilterUsed(false);
if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_CLASSPATH)) {
chooser.setMultiSelectionEnabled (true);
chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenClasses"));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
J2SEVolumeCustomizer.class,"TXT_Classpath"),new String[] {"ZIP","JAR"})); //NOI18N
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectCP"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectCP").charAt(0));
}
else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_JAVADOC)) {
chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenJavadoc"));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
J2SEVolumeCustomizer.class,"TXT_Javadoc"),new String[] {"ZIP","JAR"})); //NOI18N
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectJD"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectJD").charAt(0));
}
else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_SRC)) {
chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenSources"));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
J2SEVolumeCustomizer.class,"TXT_Sources"),new String[] {"ZIP","JAR"})); //NOI18N
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectSRC"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectSRC").charAt(0));
}
if (lastFolder != null) {
chooser.setCurrentDirectory (lastFolder);
}
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
lastFolder = chooser.getCurrentDirectory();
if (chooser.isMultiSelectionEnabled()) {
addFiles (chooser.getSelectedFiles());
}
else {
final File selectedFile = chooser.getSelectedFile();
addFiles (new File[] {selectedFile});
}
} catch (MalformedURLException mue) {
Exceptions.printStackTrace(mue);
}
}
}
public static File[] showOpenFilesDialog( final Component parent, final String title, final boolean multiselection,
final File initialPath, final FileFilter filter ) {
RunnableWithParameters runnable = new RunnableWithParameters(){
public void run() {
JFileChooser fc = new JFileChooser();
fc.setDialogTitle(title);
fc.setDialogType(JFileChooser.OPEN_DIALOG);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(multiselection);
fc.setCurrentDirectory(initialPath);
if (filter != null)
fc.setFileFilter(filter);
fc.setFileHidingEnabled(false);
int r = fc.showOpenDialog(parent);
if (r != JFileChooser.APPROVE_OPTION) {
this.returnValue = null;
return;
}
if (fc.isMultiSelectionEnabled()) {
File[] selectedFiles = fc.getSelectedFiles();
this.returnValue = selectedFiles;
} else {
File selectedFile = fc.getSelectedFile();
if (selectedFile != null && selectedFile.exists())
PreferencesHandler.setLastPath(selectedFile.getAbsolutePath());
this.returnValue = new File[]{selectedFile};
}
}
};
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (Exception e) {
Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
}
}
return (File[]) runnable.getReturnValue();
}