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

The following are Jave code examples for showing how to use setMultiSelectionEnabled() 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.
+ Save this method
Example 1
Project: pdfjumbler   File: PdfJumbler.java   View Source Code Vote up 7 votes
@Override
public void actionPerformed(ActionEvent e) {
	JFileChooser chooser = new JFileChooser(DocOpenAction.lastOpenedFileLocation);
	chooser.setMultiSelectionEnabled(true);
	chooser.setFileFilter(new FileFilter() {
		@Override
		public boolean accept(File file) {
			DocOpenAction.lastOpenedFileLocation = file.getParent();
			return
				file.isDirectory() ||
				(file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".pdf"));
		}
		
		@Override
		public String getDescription() {
			return resources.getString("FILE_FILTER_PDF");
		}
		
	});
	
	if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
		PdfJumbler.openFiles(list, -1, Arrays.asList(chooser.getSelectedFiles()));
	}
}
 
Example 2
Project: Websocket-Smart-Card-Signer   File: SignUI.java   View Source Code Vote up 7 votes
public static List<Data> showFileSelection() throws Exception{
    List<Data> ret = new ArrayList<Data>();
    
    JFileChooser jfc = new JFileChooser();
    jfc.setMultiSelectionEnabled(true);
    
    jfc.setDialogTitle("Choose the files to sign");
    SignUtils.playBeeps(1);
    if(jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
        return null;
    
    File[] choosedFileList = jfc.getSelectedFiles();
    for(File file:choosedFileList){
        String id = file.getAbsolutePath();
        byte[] fileContent = IOUtils.readFile(file);
        ret.add(new Data(id, fileContent));
    }
    return ret;
}
 
Example 3
Project: incubator-netbeans   File: MercurialOptionsPanelController.java   View Source Code Vote up 6 votes
private void onExportFilenameBrowseClick() {
    File oldFile = getExecutableFile();
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_ExportBrowseFolder"), oldFile);   // NOI18N
    fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "ExportBrowse_title"));                                            // NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    FileFilter[] old = fileChooser.getChoosableFileFilters();
    for (int i = 0; i < old.length; i++) {
        FileFilter fileFilter = old[i];
        fileChooser.removeChoosableFileFilter(fileFilter);
    }
    fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button"));                                            // NOI18N
    File f = fileChooser.getSelectedFile();
    if (f != null) {
        panel.exportFilenameTextField.setText(f.getAbsolutePath());
    }
}
 
Example 4
Project: incubator-netbeans   File: JFXIconsPanel.java   View Source Code Vote up 6 votes
private void nativeIconButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nativeIconButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new IconFileFilter(false));
    String current = nativeIconTextField.getText();
    File lastFolder = current!=null ? getFileFromPath(current) : null;
    if (lastFolder != null) {
        chooser.setSelectedFile(lastFolder);
    } else if (lastImageFolder != null) {
        chooser.setSelectedFile(lastImageFolder);
    } else { // ???
        // workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
        // chooser.setSelectedFile(new File(workDir));
    }
    chooser.setDialogTitle(NbBundle.getMessage(JFXIconsPanel.class, "LBL_Select_Icon_Image")); // NOI18N
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        String relPath = JFXProjectUtils.getRelativePath(project.getProjectDirectory(), FileUtil.toFileObject(file));
        nativeIconTextField.setText(relPath);
        lastImageFolder = file;
    }
}
 
Example 5
Project: incubator-netbeans   File: SSHKeysPanel.java   View Source Code Vote up 6 votes
private File openFile() {
    String home = System.getProperty("user.home"); // NOI18N
    JFileChooser chooser = new JFileChooser(home);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileHidingEnabled(false);
    int dlgResult = chooser.showOpenDialog(this);
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example 6
Project: school-game   File: DialogEditor.java   View Source Code Vote up 6 votes
private void loadLevel()
{
    JFileChooser chooser = new JFileChooser(lastDir == null ? PathHelper.getDialogDirIfFound() : lastDir);
    chooser.addChoosableFileFilter(filter);
    chooser.setAcceptAllFileFilterUsed(true);
    chooser.setMultiSelectionEnabled(false);

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION)
    {
        saveButton.setEnabled(false);
        replaceView(createLevelPanel);
        level = null;
        File selectedFile = chooser.getSelectedFile();
        try {
            level = DialogDataHelper.getDialogRoot(selectedFile);
            lastDir = selectedFile.getParentFile();
            saveButton.setEnabled(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Beim Laden ist ein Fehler aufgetreten!\n" + e.getMessage(), "Fehler!", JOptionPane.OK_OPTION);
        }
        rebuildTree();
    }
}
 
Example 7
Project: jaer   File: DataLogger.java   View Source Code Vote up 6 votes
public void doSelectLoggingFolder() {
    if (loggingFolder == null || loggingFolder.isEmpty()) {
        loggingFolder = System.getProperty("user.dir");
    }
    JFileChooser chooser = new JFileChooser(loggingFolder);
    chooser.setDialogTitle("Choose data logging folder");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    int retval = chooser.showOpenDialog(getChip().getAeViewer().getFilterFrame());
    if (retval == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        if (f != null && f.isDirectory()) {
            setLoggingFolder(f.toString());
            log.info("selected data logging folder " + loggingFolder);
        } else {
            log.warning("tried to select invalid logging folder named " + f);
        }
    }
}
 
Example 8
Project: jaer   File: AbstractMotionFlowIMU.java   View Source Code Vote up 6 votes
synchronized public void doSelectLoggingFolder() {
    if (loggingFolder == null || loggingFolder.isEmpty()) {
        loggingFolder = System.getProperty("user.dir");
    }
    JFileChooser chooser = new JFileChooser(loggingFolder);
    chooser.setDialogTitle("Choose data logging folder");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    if (chooser.showOpenDialog(getChip().getAeViewer().getFilterFrame()) == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        if (f != null && f.isDirectory()) {
            setLoggingFolder(f.toString());
            log.log(Level.INFO, "Selected data logging folder {0}", loggingFolder);
        } else {
            log.log(Level.WARNING, "Tried to select invalid logging folder named {0}", f);
        }
    }
}
 
Example 9
Project: incubator-netbeans   File: LocationCustomizer.java   View Source Code Vote up 6 votes
private JFileChooser getFileChooser() {
    if (fileChooser == null) {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setDialogType(JFileChooser.OPEN_DIALOG);
        chooser.setDialogTitle(Bundle.LocationCustomizer_ChooseFileDialogCaption());
        chooser.setFileFilter(new FileFilter() {
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().toLowerCase().endsWith(".java");
                } // NOI18N

                public String getDescription() {
                    return Bundle.LocationCustomizer_FileDialogFilterName();
                }
            });
        fileChooser = chooser;
    }

    return fileChooser;
}
 
Example 10
Project: jaer   File: AbstractMotionFlowIMU.java   View Source Code Vote up 6 votes
synchronized public void doImportGTfromMatlab() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Choose ground truth file");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    if (chooser.showOpenDialog(chip.getAeViewer().getFilterFrame()) == JFileChooser.APPROVE_OPTION) {
        try {
            vxGTframe = ((MLDouble) (new MatFileReader(chooser.getSelectedFile().getPath())).getMLArray("vxGT")).getArray();
            vyGTframe = ((MLDouble) (new MatFileReader(chooser.getSelectedFile().getPath())).getMLArray("vyGT")).getArray();
            tsGTframe = ((MLDouble) (new MatFileReader(chooser.getSelectedFile().getPath())).getMLArray("ts")).getArray();
            importedGTfromMatlab = true;
            log.info("Imported ground truth file");
        } catch (IOException ex) {
            log.log(Level.SEVERE, null, ex);
        }
    }
}
 
Example 11
Project: myqq   File: SendFileFrame.java   View Source Code Vote up 5 votes
/**
 * @param seletMode
 * @return 
 */
public String showDialog(int seletMode)
{
	JFileChooser chooser = new JFileChooser();
	chooser.setFileSelectionMode(seletMode);
	chooser.setMultiSelectionEnabled(true);//璁剧疆澶氶?鏂囦欢
	int result = chooser.showOpenDialog(this);
	if (result == JFileChooser.APPROVE_OPTION)
	{
		String filePath = chooser.getSelectedFile().getAbsolutePath();
		return filePath;
	}
	return null;
}
 
Example 12
Project: Cognizant-Intelligent-Test-Scripter   File: ReportDefect.java   View Source Code Vote up 5 votes
/**
 * browse and select the attachment files
 */
private void selectFile() {
    JFileChooser chooser = new JFileChooser(com.cognizant.cognizantits.ide.main.explorer.settings.Settings.getScreenShotLoc());
    chooser.setMultiSelectionEnabled(true);
    chooser.showOpenDialog(this);
    File[] files = chooser.getSelectedFiles();
    for (File f : files) {
        attachments.setText(attachments.getText() + f.getAbsolutePath() + File.pathSeparator);
    }
}
 
Example 13
Project: incubator-netbeans   File: CustomizerApplication.java   View Source Code Vote up 5 votes
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new SplashFileFilter());
    if (lastImageFolder != null) {
        chooser.setCurrentDirectory(lastImageFolder);
    }
    chooser.setDialogTitle(NbBundle.getMessage(CustomizerApplication.class, "LBL_Select_Splash_Image"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        splashTextField.setText(file.getAbsolutePath());
        lastImageFolder = file.getParentFile();
    }
}
 
Example 14
Project: call-IDE   File: InsMain.java   View Source Code Vote up 5 votes
/**
 * choose the files for moss
 */
private void chooseMossFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseMossFileBtnActionPerformed
    // TODO add your handling code here:
    JFileChooser chooseMoss = new JFileChooser();
    chooseMoss.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooseMoss.setMultiSelectionEnabled(true);
    chooseMoss.showOpenDialog(this);
    
    allMossFiles = chooseMoss.getSelectedFiles();
    for(File f : allMossFiles) {
        addedFilesArea.append(f.getAbsolutePath()+"\n");
    }
}
 
Example 15
Project: incubator-netbeans   File: ConnectionType.java   View Source Code Vote up 5 votes
protected void onBrowse(JTextField txt) {
    File oldFile = FileUtil.normalizeFile(new File(txt.getText()));
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(Repository.class, "ACSD_BrowseCertFile"), oldFile); // NOI18N
    fileChooser.setDialogTitle(NbBundle.getMessage(Repository.class, "Browse_title"));                                            // NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.showDialog(this.getPanel(), NbBundle.getMessage(Repository.class, "OK_Button"));                                            // NOI18N
    File f = fileChooser.getSelectedFile();
    if (f != null) {
        txt.setText(f.getAbsolutePath());
    }
}
 
Example 16
Project: incubator-netbeans   File: TextImporterUI.java   View Source Code Vote up 5 votes
private File selectIconFile() {
    JFileChooser dlg = new JFileChooser( defaultFolder );
    dlg.setAcceptAllFileFilterUsed( true );
    dlg.setMultiSelectionEnabled( false );
    if( dlg.showOpenDialog(this) != JFileChooser.APPROVE_OPTION )
        return null;
    defaultFolder = dlg.getCurrentDirectory();
    return dlg.getSelectedFile();
}
 
Example 17
Project: incubator-netbeans   File: InstallPanel.java   View Source Code Vote up 5 votes
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
// TODO add your handling code here:
        JFileChooser chooser = new JFileChooser(lastFolder);
        chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(InstallPanel.class, "TIT_Select_Artifact"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar"));//NOI18N
            }
            @Override
            public String getDescription() {
                return org.openide.util.NbBundle.getMessage(InstallPanel.class, "SEL_Jars");
            }
        });
        chooser.setMultiSelectionEnabled(false);
        if (txtFile.getText().trim().length() > 0) {
            File fil = new File(txtFile.getText().trim());
            if (fil.exists()) {
                chooser.setSelectedFile(fil);
            }
        }
        int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), org.openide.util.NbBundle.getMessage(InstallPanel.class, "TIT_Select"));
        if (ret == JFileChooser.APPROVE_OPTION) {
            txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
            txtFile.requestFocusInWindow();
        }

    }
 
Example 18
Project: AgentWorkbench   File: ProjectsLoaded.java   View Source Code Vote up 4 votes
/**
 * Imports a project, which is packed in Agent.GUI project file (*.agui)
 */
public void projectImport() {
	
	String optionMsg = null;
	String optionTitle = null;
	String newLine = Application.getGlobalInfo().getNewLineSeparator(); 
	
	// --- Select a *.agui file -----------------------
	String fileEnd = Application.getGlobalInfo().getFileEndProjectZip();
	FileNameExtensionFilter filter = new FileNameExtensionFilter(Language.translate("Agent.GUI Projekt-Datei") + " (*." + fileEnd + ")", fileEnd);
	
	JFileChooser chooser = new JFileChooser();
	chooser.setFileFilter(filter);
	chooser.setCurrentDirectory(Application.getGlobalInfo().getLastSelectedFolder());
	chooser.setMultiSelectionEnabled(false);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.setAcceptAllFileFilterUsed(false);
	
	int answerChooser = chooser.showDialog(Application.getMainWindow(), Language.translate("Projekt importieren"));
	if (answerChooser==JFileChooser.CANCEL_OPTION) return;
	Application.getGlobalInfo().setLastSelectedFolder(chooser.getCurrentDirectory());
	
	File projectFile = chooser.getSelectedFile();
	if (projectFile!=null && projectFile.exists()) {

		String destFolder = Application.getGlobalInfo().getPathProjects();
		String zipFolder = projectFile.getAbsolutePath();
		
		// --- Import project file as a new project ---
		Zipper zipper = CommonComponentFactory.getNewZipper(Application.getMainWindow());
		zipper.setUnzipZipFolder(zipFolder);
		zipper.setUnzipDestinationFolder(destFolder);
		
		// --- Error-Handling -------------------------
		final String rootFolder2Extract = zipper.getRootFolder2Extract();
		String testFolder = destFolder + rootFolder2Extract;
		File testFile = new File(testFolder);
		if (testFile.exists()) {
			optionTitle = rootFolder2Extract + ": " + Language.translate("Verzeichnis bereits vorhanden!");
			optionMsg = Language.translate("Verzeichnis") + ": " + testFolder + newLine;
			optionMsg+= Language.translate("Das Verzeichnis existiert bereits. Der Import wird unterbrochen.");
			JOptionPane.showMessageDialog(Application.getMainWindow(), optionMsg, optionTitle, JOptionPane.WARNING_MESSAGE);
			return;
		}
		
		// --- Define task after the unzip action -----
		Runnable afterJobTask = new Runnable() {
			@Override
			public void run() {
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						Application.getProjectsLoaded().add(rootFolder2Extract);
					}
				});
			}
		};
		zipper.setAfterJobTask(afterJobTask);
		
		// --- Finally unzip --------------------------
		zipper.doUnzipFolder();
		zipper = null;
		
	}		
	
}
 
Example 19
Project: incubator-netbeans   File: FileArrayEditorTest.java   View Source Code Vote up 4 votes
public void testSetFilesMultiSelection(){
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled( true );
    setFiles(chooser);
}
 
Example 20
Project: sumo   File: FengFonts.java   View Source Code Vote up 4 votes
/**
 * @return Returns the save path or null if the user doesn't want to save
 */
private String getSavePath() {
	JFileChooser chooser = new JFileChooser();
	chooser.setMultiSelectionEnabled(false);
	chooser.setAcceptAllFileFilterUsed(false);
	
	// restrict to *.png files
	FileFilter ff = new FileFilter() {
		public boolean accept(File f) {
			return f.getName().toLowerCase().endsWith(".png") 
	          || f.isDirectory();
		}
		
		public String getDescription() {
	        return "PNG";
	      }
	};
	
	chooser.setFileFilter(ff);
	
	File chosenFile = null;
	int option = chooser.showSaveDialog(this);
	if(option == JFileChooser.APPROVE_OPTION) {
		chosenFile = chooser.getSelectedFile();
	} else if(option == JFileChooser.CANCEL_OPTION) {
		return null;
	}
	
	if(chosenFile!=null&&chosenFile.canRead()) {
		int opt = JOptionPane.showConfirmDialog(this, 
				"Overwrite existing file?", 
				"FontCreator",
				JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE);
		
		if(opt == JOptionPane.CANCEL_OPTION) {
			return null;
		}
		if(opt == JOptionPane.NO_OPTION) {
			return null;
		}
	}
	
	if(chosenFile != null) {
		return chosenFile.getAbsolutePath();
	}
	else
		return null;
}