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

The following are Jave code examples for showing how to use setSelectedFiles() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: LibraryStartVisualPanel.java   Source Code and License Vote up 7 votes
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 2
Project: incubator-netbeans   File: OpenProject.java   Source Code and License Vote up 6 votes
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 3
Project: rapidminer   File: FileChooserUI.java   Source Code and License Vote up 5 votes
@Override
public void actionPerformed(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", "");

	try {
		if (name != null && !"".equals(name)) {
			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 4
Project: marathonv5   File: JFileChooserJavaElement.java   Source Code and License Vote up 5 votes
@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 5
Project: smile_1.5.0_java7   File: PlotPanel.java   Source Code and License Vote up 5 votes
/**
 * Shows a file chooser and exports the plot to the selected image file.
 * @throws IOException if an error occurs during writing.
 */
public void save() throws IOException {
    JFileChooser fc = FileChooser.getInstance();
    fc.setFileFilter(FileChooser.SimpleFileFilter.getWritableImageFIlter());
    fc.setAcceptAllFileFilterUsed(false);
    fc.setSelectedFiles(new File[0]);
    int returnVal = fc.showSaveDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        save(file);
    }        
}