private void doLoadFiles() { if (chooser == null) { chooser = createFileChooser(); } String approveText = chooser.getApproveButtonText(); chooser.setApproveButtonText("Load with file filters"); int status = chooser.showOpenDialog(this); chooser.setApproveButtonText(approveText); if (status == JFileChooser.APPROVE_OPTION) { //now set up the file filters if there are directories File[] selectedFiles = chooser.getSelectedFiles(); boolean haveDirectory = false; for (File f : selectedFiles) { if (f.isDirectory()) { haveDirectory = true; break; } } if (haveDirectory) { doFileFilters(selectedFiles); } else { startFileLoadingThread(new EnumMap<>(FilterType.class), selectedFiles); } } }
private void loadReport() { final JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Choose scanner report directory"); File lastReport = getLastUsedReport(); if (lastReport != null) { fc.setCurrentDirectory(lastReport); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileHidingEnabled(false); fc.setApproveButtonText("Open scanner report"); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try { setLastUsedReport(file); loadReport(file); } catch (Exception e) { JOptionPane.showMessageDialog(frame, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); exit(); } } else { exit(); } }
chooser.setApproveButtonText(approveText);
) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
/** * Creates a {@code JFileChooser} component and sets it to be for directories only. * * @param parent the component from where the chooser will be launched <i>(should be the main panel of the application)</i>. */ public DirChooser(Component parent) { this.parent = parent; dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); dirChooser.setDialogTitle(String.format(I18n.INSTANCE.get("dirchooser.title"), Configuration.INSTANCE.get("application.name"))); dirChooser.setApproveButtonText(I18n.INSTANCE.get("dirchooser.approve.btn")); }
) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
private JFileChooser createChooserForDirectorySelection() { JFileChooser chooser; chooser = new JFileChooser(nameTF.getText()); chooser.setApproveButtonText("Select Folder"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); return chooser; }
JFileChooser chooser = new JFileChooser(); chooser.setApproveButtonText("Save"); int result = chooser.showOpenDialog(null); if(result == JFileChooser.APPROVE_OPTION){ File selection = chooser.getSelectedFile(); //verify if file exists if(selection.exists()){ //you can continue the code here or call the next method or just use !exists and behavior for wrong file }else{ //System.exit(0), show alert.. etc } }
JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setDialogTitle("Select a folder"); fc.setApproveButtonText(SELECT); if(fc.showOpenDialog(singleton) == JFileChooser.APPROVE_OPTION) { File folder = fc.getSelectedFile(); String path = folder.getPath() + File.separatorChar + "MYAPPFOLDER"; }
public static String openFile(String fileExtension) { JFileChooser dlgFile = new JFileChooser(); dlgFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); dlgFile.setApproveButtonText("Open"); int returnVal = dlgFile.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = dlgFile.getSelectedFile(); return file.getAbsolutePath(); } return ""; }
private void buttonGraphvizDotFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGraphvizDotFileActionPerformed final JFileChooser fileChooser = new JFileChooser(this.textFieldPathToGraphvizDot.getText()); fileChooser.setDialogTitle("Select GraphViz dot executable file"); fileChooser.setApproveButtonText("Select"); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final File file = fileChooser.getSelectedFile(); this.textFieldPathToGraphvizDot.setText(file.getAbsolutePath()); } }//GEN-LAST:event_buttonGraphvizDotFileActionPerformed
@Override public void actionPerformed(ActionEvent evt) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(true); chooser.setApproveButtonText("Choose"); chooser.setDialogTitle("Choose the directory"); if (chooser.showOpenDialog(SourceDirectoryWizard.this) == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = chooser.getSelectedFiles(); for (File selectedFile : selectedFiles) { sourceRootBox.setText(selectedFile.getAbsolutePath()); } nextButton.setEnabled(!"".equals(sourceRootBox.getText())); } } });
private File fileChooser(String title, JFrame frame, boolean dirOnly) { // Prompt user to choose their Cockpit home directory. JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setDialogTitle(title); fileChooser.setFileSelectionMode( (dirOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY)); fileChooser.setApproveButtonText("Select " + (dirOnly ? "Directory" : "File")); int returnVal = fileChooser.showOpenDialog(frame); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } else { return fileChooser.getSelectedFile(); } }
private void browse() { if (fileChooser == null) { fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Select"); fileChooser.setDialogTitle("Select a directory"); fileChooser.setSelectedFile(new File(directoryField.getText())); } fileChooser.setCurrentDirectory(new File(directoryField.getText())); int value = fileChooser.showDialog(this, null); if (value == JFileChooser.APPROVE_OPTION) { directoryField.setText(fileChooser.getSelectedFile().getPath()); } }
private File fileChooser(String title, JFrame frame, boolean dirOnly) { // Prompt user to choose their Cockpit home directory. JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setDialogTitle(title); fileChooser.setFileSelectionMode( (dirOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY)); fileChooser.setApproveButtonText("Select " + (dirOnly ? "Directory" : "File")); int returnVal = fileChooser.showOpenDialog(frame); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } else { return fileChooser.getSelectedFile(); } }
public void actionPerformed(ActionEvent e) { // lazily create the file chooser if (fileChooser == null) { fileChooser = new JFileChooser(); fileChooser.setApproveButtonText("Select"); fileChooser.setDialogTitle("Select a PNG file"); fileChooser.addChoosableFileFilter(new PngFileFilter()); fileChooser.setSelectedFile(new File(fileNameField.getText())); } // select a File int value = fileChooser.showDialog(this, null); if (value == JFileChooser.APPROVE_OPTION) { fileNameField.setText(fileChooser.getSelectedFile().getPath()); } } }
private void chooseFolder() { // Prompt user to choose their Cockpit home directory. JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setDialogTitle("Choose Cockpit Home Folder"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Choose Folder"); fileChooser.setCurrentDirectory(cockpitHomeFolder); int returnVal = fileChooser.showOpenDialog(ownerFrame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } else { this.cockpitHomeFolder = fileChooser.getSelectedFile(); this.folderPathTextField.setText(this.cockpitHomeFolder.getAbsolutePath()); refreshStoredCredentialsTable(); } }
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(Bundle.CreateSiteTemplate_FileChooser()); chooser.setMultiSelectionEnabled(false); chooser.setApproveButtonText(Bundle.CreateSiteTemplate_FileChooserButton()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showDialog(this, null) == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); if (f.isFile()) { f = f.getParentFile(); } fileTextField.setText(f.getAbsolutePath()); } }//GEN-LAST:event_browseButtonActionPerformed
public void actionPerformed( ActionEvent e ) { JFileChooser chooser = new JFileChooser(); chooser.setApproveButtonText( "Convert to MITAB25" ); // Enable multiple selections chooser.setMultiSelectionEnabled( true ); // Show the dialog; wait until dialog is closed chooser.showOpenDialog( frame ); // Retrieve the selected files. This method returns empty // if multiple-selection mode is not enabled. File[] files = chooser.getSelectedFiles(); if ( files != null && files.length > 0 ) { FilesProcessor processor = new FilesProcessor(); processor.process( frame, files, expansionStrategy, postProcessorStrategy, aggregateSelectedFiles ); } } } );
private JFileChooser getFileChooser() { if (fileChooser == null) { // File chooser fileChooser = new JFileChooser(); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle(Bundle.ExportAction_ExportDialogTitle()); fileChooser.setApproveButtonText(Bundle.ExportAction_ExportDialogButton()); } fileChooser.resetChoosableFileFilters(); setFilters(); return fileChooser; }