Java Code Examples for javax.swing.JFileChooser#setSelectedFiles()

The following examples show how to use javax.swing.JFileChooser#setSelectedFiles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFileChooserJavaElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: LibraryStartVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void browseLibraryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLibraryButtonActionPerformed
    JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastChosenLibraryLocation());
    File[] olds = convertStringToFiles(txtLibrary.getText().trim());
    chooser.setSelectedFiles(olds);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);
    chooser.addChoosableFileFilter(new JarZipFilter());
    int ret = chooser.showDialog(this, getMessage("LBL_Select"));
    if (ret == JFileChooser.APPROVE_OPTION) {
        File[] files =  chooser.getSelectedFiles();
        if (files.length == 0) {
            return;
        }
        String path = "";
        for (int i = 0; i < files.length; i++) {
            path = path + files[i] + ( i == files.length - 1 ? "" : File.pathSeparator);
        }
        txtLibrary.setText(path);
        ModuleUISettings.getDefault().setLastChosenLibraryLocation(files[0].getParentFile().getAbsolutePath());
    }
}
 
Example 3
Source File: OpenProject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void actionPerformed(ActionEvent evt) {
    JFileChooser chooser = ProjectChooserAccessory.createProjectChooser( true ); // Create the jFileChooser
    chooser.setMultiSelectionEnabled( true );
    
    // Check to see if the current selection matches a file/folder owned by a non-open project;
    // if so, use that as the starting directory, as a convenience in case that is what should be opened.
    // XXX may also want to check lookup for FileObject
    for (DataObject d : Utilities.actionsGlobalContext().lookupAll(DataObject.class)) {
        Project selected = FileOwnerQuery.getOwner(d.getPrimaryFile());
        if (selected != null && !OpenProjectList.getDefault().isOpen(selected)) {
            File dir = FileUtil.toFile(selected.getProjectDirectory());
            if (dir != null) {
                chooser.setCurrentDirectory(dir.getParentFile());
                chooser.setSelectedFiles(new File[] {dir});
                break;
            }
        }
    }
    show(chooser);
}
 
Example 4
Source File: FileChooserUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example 5
Source File: Preferences.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
void apply(JFileChooser jfc) {
     jfc.setLocation(location);
     if(selection.length == 1) {
if(selection[0] != null)
  jfc.setSelectedFile(selection[0]);
     } else
jfc.setSelectedFiles(selection);
   }