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

The following are Jave code examples for showing how to use showDialog() 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: Ultraino   File: FileUtils.java   Source Code and License Vote up 6 votes
public static String selectDirectory(Component component,String name,File pathToUse){

        JFileChooser chooser = new JFileChooser();
        boolean useIndicated = pathToUse != null;
        if (useIndicated && lastIndicatedPath == null){
            lastIndicatedPath = pathToUse;
        }

        chooser.setCurrentDirectory(useIndicated?lastIndicatedPath:lastChooserPath);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	int result = chooser.showDialog(component, name);
        if ( result == JFileChooser.APPROVE_OPTION){
            try{
                if(useIndicated){
                    lastIndicatedPath = chooser.getCurrentDirectory();
                }else{
                    lastChooserPath = chooser.getCurrentDirectory();
                }
                return chooser.getSelectedFile().getAbsolutePath();
            }catch(Exception e){e.printStackTrace();}
        }
        return null;
    }
 
Example 3
Project: incubator-netbeans   File: CheckoutUI.java   Source Code and License Vote up 6 votes
@Messages({"TIT_Choose=Choose Directory To Check Out", "LBL_Select=Select"})
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
    JFileChooser chooser = new JFileChooser(lastFolder);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setDialogTitle(TIT_Choose());

    chooser.setMultiSelectionEnabled(false);
    if (txtFolder.getText().trim().length() > 0) {
        File fil = new File(txtFolder.getText().trim());
        if (fil.exists()) {
            chooser.setSelectedFile(fil);
        }
    }
    int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), LBL_Select());
    if (ret == JFileChooser.APPROVE_OPTION) {
        txtFolder.setText(chooser.getSelectedFile().getAbsolutePath());
        txtFolder.requestFocusInWindow();
    }
}
 
Example 4
Project: applecommander   File: SwingAppleCommander.java   Source Code and License Vote up 6 votes
/**
 * Open a file.
 */
protected void openFile() {
	JFileChooser jc = new JFileChooser();
	String pathName = userPreferences.getDiskImageDirectory();
	if (null == pathName) {
		pathName = ""; //$NON-NLS-1$
		}
	jc.setCurrentDirectory(new File(pathName));
	EmulatorFileFilter ff = new EmulatorFileFilter();
	jc.setFileFilter(ff);
	int rc = jc.showDialog(this, textBundle.get("Open")); //$NON-NLS-1$
	if (rc == 0) {
		userPreferences.setDiskImageDirectory(jc.getSelectedFile().getParent());
		UserPreferences.getInstance().save();
		addDiskExplorerTab(jc.getSelectedFile());
	}
}
 
Example 5
Project: AppleCommander   File: SwingAppleCommander.java   Source Code and License Vote up 6 votes
/**
 * Open a file.
 */
protected void openFile() {
	JFileChooser jc = new JFileChooser();
	String pathName = userPreferences.getDiskImageDirectory();
	if (null == pathName) {
		pathName = ""; //$NON-NLS-1$
		}
	jc.setCurrentDirectory(new File(pathName));
	EmulatorFileFilter ff = new EmulatorFileFilter();
	jc.setFileFilter(ff);
	int rc = jc.showDialog(this, textBundle.get("Open")); //$NON-NLS-1$
	if (rc == 0) {
		userPreferences.setDiskImageDirectory(jc.getSelectedFile().getParent());
		UserPreferences.getInstance().save();
		addDiskExplorerTab(jc.getSelectedFile());
	}
}
 
Example 6
Project: Ultraino   File: FileUtils.java   Source Code and License Vote up 5 votes
public static String selectFile(Component component, String name, String extension, File pathToUse){
       JFileChooser chooser = new JFileChooser();
       if(extension != null){        
           chooser.setFileFilter(new ExtensionFilter(extension));
       }
       
       boolean useGivenPath = pathToUse != null;
       if (useGivenPath && lastIndicatedPath == null){
           lastIndicatedPath = pathToUse;
       }
       chooser.setCurrentDirectory(useGivenPath?lastIndicatedPath:lastChooserPath);
int result = chooser.showDialog(component, name);
       if ( result == JFileChooser.APPROVE_OPTION){
           try{
               if(useGivenPath){
                   lastIndicatedPath = chooser.getCurrentDirectory();
               }else{
                   lastChooserPath = chooser.getCurrentDirectory();
               }
               String p = chooser.getSelectedFile().getAbsolutePath();
               if (extension.startsWith(".")){
                   if (p.endsWith(extension)){
                       return p;
                   }else{
                       return p + extension;
                   }
               }else{
                   if (p.endsWith(extension)){
                       return p;
                   }else{
                       return p + "." + extension;
                   }
               }
              
           }catch(Exception e){e.printStackTrace();}
       }

       return null;
   }
 
Example 7
Project: incubator-netbeans   File: LibraryStartVisualPanel.java   Source Code and License Vote up 5 votes
private void browseLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLicenceButtonActionPerformed
    JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastChosenLibraryLocation());
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    if (txtLicense.getText().trim().length() > 0) {
        chooser.setSelectedFile(new File(txtLicense.getText().trim()));
    }
    int ret = chooser.showDialog(this, getMessage("LBL_Select"));
    if (ret == JFileChooser.APPROVE_OPTION) {
        txtLicense.setText(chooser.getSelectedFile().getAbsolutePath());
        ModuleUISettings.getDefault().setLastChosenLibraryLocation(txtLicense.getText());
    }
}
 
Example 8
Project: incubator-netbeans   File: InstallPanel.java   Source Code and License 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 9
Project: incubator-netbeans   File: InstallDocSourcePanel.java   Source Code and License Vote up 5 votes
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
    JFileChooser chooser = new JFileChooser(lastFolder);
    chooser.setDialogTitle(isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_javadoc_zip")
                                       : NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_source_zip"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".zip")); //NOI18N
        }
        @Override
        public String getDescription() {
            
            return isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_javadoc_zip")
                               : NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_source_zip");
        }
    });
    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), BTN_Select());
    if (ret == JFileChooser.APPROVE_OPTION) {
        txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
        txtFile.requestFocusInWindow();
    }

}
 
Example 10
Project: incubator-netbeans   File: ConnectionType.java   Source Code and License 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 11
Project: incubator-netbeans   File: AdvancedLocationPanel.java   Source Code and License Vote up 5 votes
@Messages("LBL_Select=Select")
private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
    JFileChooser jfc = new JFileChooser();
    
    jfc.setSelectedFile(new File(standard.getProjectLocation(), fileLocation.getText()));
    
    if (jfc.showDialog(this, Bundle.LBL_Select()) == JFileChooser.APPROVE_OPTION) {
        fileLocation.setText(standard.getProjectLocation().toURI().relativize(jfc.getSelectedFile().toURI()).getPath());
    }
}
 
Example 12
Project: incubator-netbeans   File: ImageCacheTest.java   Source Code and License Vote up 5 votes
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    JFileChooser jfc = new JFileChooser ();
    jfc.setFileSelectionMode(jfc.DIRECTORIES_ONLY);
    jfc.showDialog(this, "Choose a directory with cache files");
   

    File fi = jfc.getSelectedFile();
    
    try {
        if (fi==null || (!fi.exists() && !fi.isDirectory())) {
            System.err.println("I can't do that: " + fi);
            return;
        }
        CacheReader r = new CacheReader (fi);
        String[] s = r.getIDs();
        for (int i=0; i < s.length; i++) {
            File f = new File(s[i]);
            BufferedImage img = (BufferedImage) r.find(s[i]);
            ImagePanel ip = new ImagePanel(img);
            ip.setName ("c-" + s[i]);
            jTabbedPane2.insertTab(f.getName(), null, new JScrollPane(ip), f.toString(), 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    
}
 
Example 13
Project: incubator-netbeans   File: MercurialOptionsPanelController.java   Source Code and License Vote up 5 votes
private void onExecPathBrowseClick() {
    File oldFile = getExportFile();
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_BrowseFolder"), oldFile);   // NOI18N
    fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "Browse_title"));                                            // NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button"));                                            // NOI18N
    File f = fileChooser.getSelectedFile();
    if (f != null) {
        panel.executablePathTextField.setText(f.getAbsolutePath());
    }
}
 
Example 14
Project: incubator-netbeans   File: NbClassPathCustomEditor.java   Source Code and License Vote up 5 votes
private void addDirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDirButtonActionPerformed
      JFileChooser chooser = FileEditor.createHackedFileChooser();
      chooser.setFileHidingEnabled(false);
      setHelpToChooser( chooser );
      chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      chooser.setDialogTitle(getString("CTL_FileSystemPanel.Local_Dialog_Title"));

      if (lastDirFolder != null) {
          chooser.setCurrentDirectory(lastDirFolder);
      }

      if (chooser.showDialog(this,
                             getString("CTL_Approve_Button_Title"))
              == JFileChooser.APPROVE_OPTION) {
          File f = chooser.getSelectedFile();
          if ((f != null) && (f.isDirectory())) {
              lastDirFolder = f.getParentFile();

              String path = f.getAbsolutePath();
              if (! listModel.contains (path)) {
                  listModel.addElement (path);
              }
              fireValueChanged();
              
              pathList.setSelectedIndex(listModel.size() - 1);
          }
      }
}
 
Example 15
Project: incubator-netbeans   File: NameAndLocationPanel.java   Source Code and License Vote up 5 votes
private void btnIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIconActionPerformed
    JFileChooser chooser = WizardUtils.getIconFileChooser(txtIcon.getText());
    int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N
    if (ret == JFileChooser.APPROVE_OPTION) {
        File file =  chooser.getSelectedFile();
        txtIcon.setText(file.getAbsolutePath());
    }
}
 
Example 16
Project: jaer   File: TimestampCalibrator.java   Source Code and License Vote up 5 votes
synchronized public void doSelectLoggingFolder() {
    JFileChooser c = new JFileChooser(lastLoggingFolder);
    c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int ret = c.showDialog(chip.getAeViewer().getFilterFrame(), "Select folder");
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    lastLoggingFolder = c.getSelectedFile().getPath();
    putString("lastLoggingFolder", lastLoggingFolder);
    tobiLogger = new TobiLogger(lastLoggingFolder + File.separator + "TimestampCalibrator", "SystemTimeMillis dtClockNs dtTsUs");
    tobiLogger.setAbsoluteTimeEnabled(true);
    tobiLogger.setEnabled(true);// creates log file
    tobiLogger.addComment("timestamp calibrator log file");

}
 
Example 17
Project: brModelo   File: Dialogos.java   Source Code and License Vote up 5 votes
public static String ShowDlgFileImg(JComponent form) {
    JFileChooser f = new JFileChooser();
    //f.setDialogTitle(Editor.fromConfiguracao.getValor("Controler.dlg.image"));
    int returnVal = f.showDialog(form, Editor.fromConfiguracao.getValor("Controler.dlg.image"));
    f.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = f.getSelectedFile();
        return file.getAbsolutePath();
    } else {
        return null;
    }
}
 
Example 18
Project: incubator-netbeans   File: NameIconLocationPanel.java   Source Code and License Vote up 5 votes
private void iconButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iconButtonActionPerformed
    JFileChooser chooser = WizardUtils.getIconFileChooser(icon.getText());
    int ret = chooser.showDialog(this, getMessage("LBL_Select"));
    if (ret == JFileChooser.APPROVE_OPTION) {
        File iconFile =  FileUtil.normalizeFile(chooser.getSelectedFile());
            icon.setText(iconFile.getAbsolutePath());
            Set<File> allFiles = getPossibleIcons(getIconPath());
            if (!allFiles.remove(iconFile)) {
                return; // #186459: user somehow selected a directory
            }
            boolean isIconSmall = WizardUtils.isValidIcon(iconFile, 16, 16);
 
            File secondIcon = null;
            boolean isSecondIconSmall = false;
            for (Iterator<File> it = allFiles.iterator(); it.hasNext() && !isSecondIconSmall;) {
                File f = it.next();
                isSecondIconSmall = (isIconSmall) ? 
                    WizardUtils.isValidIcon(f, 24, 24) : WizardUtils.isValidIcon(f, 16, 16);
                if (isSecondIconSmall) {
                    secondIcon = f;
                    break;
                }
            }
            
            if (secondIcon != null) {
                smallIconPath = (isIconSmall) ? iconFile : secondIcon;
                largeIconPath = (isIconSmall) ? secondIcon : iconFile;
            } else {
                smallIconPath = iconFile;
                largeIconPath = null;
            }
            
        updateData();
    }
}
 
Example 19
Project: Tarski   File: EditorActions.java   Source Code and License Vote up 4 votes
/**
 * 
 */
public void actionPerformed(ActionEvent e) {
  BasicGraphEditor editor = getEditor(e);

  if (editor != null) {
    if (!editor.isModified() || JOptionPane.showConfirmDialog(editor,
        mxResources.get("loseChanges")) == JOptionPane.YES_OPTION) {
      mxGraph graph = editor.getGraphComponent().getGraph();

      if (graph != null) {
        String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir");

        JFileChooser fc = new JFileChooser(wd);

        // Adds file filter for supported file format
        DefaultFileFilter defaultFilter = new DefaultFileFilter(".mxe",
            mxResources.get("allSupportedFormats") + " (.mxe, .png, .vdx)") {

          public boolean accept(File file) {
            String lcase = file.getName().toLowerCase();

            return super.accept(file) || lcase.endsWith(".png") || lcase.endsWith(".vdx");
          }
        };
        fc.addChoosableFileFilter(defaultFilter);

        fc.addChoosableFileFilter(new DefaultFileFilter(".mxe",
            "mxGraph Editor " + mxResources.get("file") + " (.mxe)"));
        fc.addChoosableFileFilter(
            new DefaultFileFilter(".png", "PNG+XML  " + mxResources.get("file") + " (.png)"));

        // Adds file filter for VDX import
        fc.addChoosableFileFilter(new DefaultFileFilter(".vdx",
            "XML Drawing  " + mxResources.get("file") + " (.vdx)"));

        // Adds file filter for GD import
        fc.addChoosableFileFilter(new DefaultFileFilter(".txt",
            "Graph Drawing  " + mxResources.get("file") + " (.txt)"));

        fc.setFileFilter(defaultFilter);

        int rc = fc.showDialog(null, mxResources.get("openFile"));

        if (rc == JFileChooser.APPROVE_OPTION) {
          lastDir = fc.getSelectedFile().getParent();

          try {
            if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png")) {
              openXmlPng(editor, fc.getSelectedFile());
            } else if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".txt")) {
              openGD(editor, fc.getSelectedFile(),
                  mxUtils.readFile(fc.getSelectedFile().getAbsolutePath()));
            } else {
              Document document =
                  mxXmlUtils.parseXml(mxUtils.readFile(fc.getSelectedFile().getAbsolutePath()));

              mxCodec codec = new mxCodec(document);
              codec.decode(document.getDocumentElement(), graph.getModel());
              editor.setCurrentFile(fc.getSelectedFile());

              resetEditor(editor);
            }
          } catch (IOException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(editor.getGraphComponent(), ex.toString(),
                mxResources.get("error"), JOptionPane.ERROR_MESSAGE);
          }
        }
      }
    }
  }
}
 
Example 20
Project: incubator-netbeans   File: NbClassPathCustomEditor.java   Source Code and License Vote up 4 votes
private void addJarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addJarButtonActionPerformed

        JFileChooser chooser = FileEditor.createHackedFileChooser();
        chooser.setFileHidingEnabled(false);
        setHelpToChooser( chooser );
        
        chooser.setFileFilter(new FileFilter() {
                                  public boolean accept(File f) {
                                      return (f.isDirectory() || f.getName().endsWith(".jar") || f.getName().endsWith(".zip")); // NOI18N
                                  }
                                  public String getDescription() {
                                      return getString("CTL_JarArchivesMask");
                                  }
                              });

        if (lastJarFolder != null) {
            chooser.setCurrentDirectory(lastJarFolder);
        }

        chooser.setDialogTitle(getString("CTL_FileSystemPanel.Jar_Dialog_Title"));
        chooser.setMultiSelectionEnabled( true );
        if (chooser.showDialog(this,
                               getString("CTL_Approve_Button_Title"))
                == JFileChooser.APPROVE_OPTION) {
            File[] files = chooser.getSelectedFiles();
            boolean found = false;
            for (int i=0; i<files.length; i++) {
                if ((files[i] != null) && (files[i].isFile())) {
                    found = true;
                    String path = files[i].getAbsolutePath();
                    if (! listModel.contains (path)) {
                        listModel.addElement (path);
                    }
                }
            }
            if ( found ) {
                lastJarFolder = chooser.getCurrentDirectory();
                fireValueChanged();
            }
            pathList.setSelectedIndex(listModel.size() - 1);
        }
  }