javax.swing.JFileChooser#showOpenDialog ( )源码实例Demo

下面列出了javax.swing.JFileChooser#showOpenDialog ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseButtonActionPerformed
    JFileChooser chooser = new JFileChooser(new FXMLTemplateWizardIterator.SrcFileSystemView(support.getSourceGroupsAsFiles()));
    chooser.setDialogTitle(NbBundle.getMessage(ConfigureFXMLControllerPanelVisual.class, "LBL_ConfigureFXMLPanel_FileChooser_Select_Controller")); // NOI18N
    chooser.setFileFilter(FXMLTemplateWizardIterator.FXMLTemplateFileFilter.createJavaFilter());
    String existingPath = existingNameTextField.getText();
    if (existingPath.length() > 0) {
        File f = new File(support.getCurrentChooserFolder().getPath() + File.pathSeparator + existingPath);
        if (f.exists()) {
            chooser.setSelectedFile(f);
        } else {
            chooser.setCurrentDirectory(FileUtil.toFile(support.getCurrentChooserFolder()));
        }
    } else {
        chooser.setCurrentDirectory(FileUtil.toFile(support.getCurrentChooserFolder()));
    }
    
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        String controllerClass = FileUtil.normalizeFile(chooser.getSelectedFile()).getPath();
        // XXX check other roots ?
        final String srcPath = FileUtil.normalizeFile(FileUtil.toFile(support.getCurrentSourceGroupFolder())).getPath();
        final String relativePath = controllerClass.substring(srcPath.length() + 1);
        final String relativePathWithoutExt = relativePath.substring(0, relativePath.indexOf(FXMLTemplateWizardIterator.JAVA_FILE_EXTENSION));
        existingNameTextField.setText(relativePathWithoutExt.replace(File.separatorChar, '.')); // NOI18N
    }
}
 
源代码2 项目: nextreports-designer   文件: ImageChooser.java
public static String showDialog(Component parent, String title, String initialImage) {
			
	JFileChooser fc = new JFileChooser();
       ImagePreviewPanel previewPane = new ImagePreviewPanel();
       fc.setAccessory(previewPane);
       fc.addPropertyChangeListener(previewPane);
       fc.setDialogTitle(I18NSupport.getString("image.title"));
       fc.setAcceptAllFileFilterUsed(false);
       fc.addChoosableFileFilter(new ImageFilter());
       
       int returnVal = fc.showOpenDialog(Globals.getMainFrame());
       if (returnVal == JFileChooser.APPROVE_OPTION) {
           final File f = fc.getSelectedFile();
           if (f != null) {
           	 try {
                    FileUtil.copyToDir(f, new File(Globals.getCurrentReportAbsolutePath()).getParentFile(), true);                
                } catch (IOException e) {
                    e.printStackTrace();  
                }
           	return f.getName();
           }            
       } 
       return null;        		       
}
 
源代码3 项目: netbeans   文件: OutputPanel.java
private void javadocBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javadocBrowseActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setMultiSelectionEnabled(false);
    if (lastChosenFile != null) {
        chooser.setSelectedFile(lastChosenFile);
    } else if (javadoc.getText().length() > 0) {
        chooser.setSelectedFile(new File(javadoc.getText()));
    } else {
        File files[] = model.getBaseFolder().listFiles();
        if (files != null && files.length > 0) {
            chooser.setSelectedFile(files[0]);
        } else {
            chooser.setSelectedFile(model.getBaseFolder());
        }
    }
    chooser.setDialogTitle(NbBundle.getMessage(OutputPanel.class, "LBL_Browse_Javadoc")); // NOI18N
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = chooser.getSelectedFile();
        file = FileUtil.normalizeFile(file);
        javadoc.setText(file.getAbsolutePath());
        lastChosenFile = file;
    }
}
 
源代码4 项目: Websocket-Smart-Card-Signer   文件: SignUI.java
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;
}
 
源代码5 项目: procamtracker   文件: MainFrame.java
private void settingsLoadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsLoadMenuItemActionPerformed
    JFileChooser fc = new JFileChooser();
    if (settingsFile != null) {
        fc.setSelectedFile(settingsFile);
    } else {
        fc.setSelectedFile(DEFAULT_SETTINGS_FILE);
    }
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {
            loadSettings(file);
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE,
                    "Could not load settings from \"" + file + "\"", ex);
        }
    }

}
 
源代码6 项目: netbeans   文件: PanelProjectLocationVisual.java
private void browseLocationAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationAction
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) { // NOI18N
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(NbBundle.getMessage(PanelSourceFolders.class, "LBL_NWP1_SelectProjectLocation")); // NOI18N
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = this.projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File(path);
            if (f.exists()) {
                chooser.setSelectedFile(f);
            }
        }
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
        }
        panel.fireChangeEvent();
    }
}
 
private void jButton1ActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // Add your handling code here:
    JFileChooser chooser = org.netbeans.beaninfo.editors.FileEditor.createHackedFileChooser();
    chooser.setMultiSelectionEnabled (false);
    File init = new File(processField.getText()); // #13372
    if (init.isFile()) {
        chooser.setCurrentDirectory(init.getParentFile());
        chooser.setSelectedFile(init);
    }
    int retVal = chooser.showOpenDialog (this);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        String absolute_name = chooser.getSelectedFile ().getAbsolutePath ();
        //System.out.println("file:" + absolute_name); // NOI18N
        processField.setText (absolute_name);
    }
}
 
源代码8 项目: visualvm   文件: OpenHeapWalkerAction.java
private static File getHeapDumpFile() {
    JFileChooser chooser = new JFileChooser();

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

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
    chooser.addChoosableFileFilter(new FileFilterImpl());
    chooser.setDialogTitle(
        Bundle.OpenHeapWalkerAction_DialogCaption()
    );

    if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) {
        importDir = chooser.getCurrentDirectory();

        return chooser.getSelectedFile();
    }

    return null;
}
 
源代码9 项目: rcrs-server   文件: ScenarioEditor.java
/**
   Load a map and scenario by showing a file chooser dialog.
   @throws CancelledByUserException If the user cancels the change due to unsaved changes.
   @throws MapException If there is a problem reading the map.
   @throws ScenarioException If there is a problem reading the scenario.
 * @throws rescuecore2.scenario.exceptions.ScenarioException
*/
public void load() throws CancelledByUserException, MapException, ScenarioException, rescuecore2.scenario.exceptions.ScenarioException {
    JFileChooser chooser = new JFileChooser(baseDir);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return f.isDirectory();
            }

            @Override
            public String getDescription() {
                return "Directories";
            }
        });
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        load(chooser.getSelectedFile());
    }
}
 
源代码10 项目: PolyGlot   文件: ScrPrintToPDF.java
private void btnSelectSavePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectSavePathActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Save Language");
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf");
    String fileName = core.getCurFileName().replaceAll(".pgd", ".pdf");
    chooser.setFileFilter(filter);
    chooser.setApproveButtonText("Save");
    chooser.setCurrentDirectory(core.getWorkingDirectory());
    chooser.setSelectedFile(new File(fileName));

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        fileName = chooser.getSelectedFile().getAbsolutePath();
        if (!fileName.contains(".pdf")) {
            fileName += ".pdf";
        }            
        txtSavePath.setText(fileName);
    }
}
 
源代码11 项目: netbeans   文件: BasicProjectInfoPanel.java
private void browseAntScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseAntScriptActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
    if (antScript.getText().length() > 0 && getAntScript().exists()) {
        chooser.setSelectedFile(getAntScript());
    } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
        chooser.setSelectedFile(getProjectLocation());
    } else {
        chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
    }
    chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Build_Script"));  //NOI18N
    if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File script = FileUtil.normalizeFile(chooser.getSelectedFile());
        antScript.setText(script.getAbsolutePath());
    }            
}
 
源代码12 项目: bytecode-viewer   文件: MainViewerGUI.java
public void library()
{
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter()
    {
        @Override
        public boolean accept(File f)
        {
            return f.isDirectory();
        }

        @Override
        public String getDescription()
        {
            return "Optional Library Folder";
        }
    });
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setFileHidingEnabled(false);
    fc.setAcceptAllFileFilterUsed(false);
    int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);

    if (returnVal == JFileChooser.APPROVE_OPTION)
        try
        {
            BytecodeViewer.library = fc.getSelectedFile().getAbsolutePath();
        }
        catch (Exception e1)
        {
            new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
        }
}
 
源代码13 项目: psychoPATH   文件: PsychoPanel2.java
private void webrootLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_webrootLoadButtonActionPerformed
   JFileChooser fc = new JFileChooser();
   int returnVal = fc.showOpenDialog(PsychoPanel2.this);
   if (returnVal == JFileChooser.APPROVE_OPTION) 
   {
        Scanner inFile1;
        try {
           inFile1 = new Scanner(fc.getSelectedFile()).useDelimiter("\\r*\\n");
        } catch (FileNotFoundException ex) {
           Logger.getLogger(PsychoPanel2.class.getName()).log(Level.SEVERE, null, ex);
           return;
        }
        List<String> temps = new ArrayList<>();            
        while (inFile1.hasNext()) 
        {
            String line = inFile1.next();
            temps.add(line);
        }
        inFile1.close();
        //suffixesList.setListData((String[])temps.toArray());
        // for some reason casting (String[]) on toArray() does not work as expected (empty data list)            
        //String[] empty={};
        //docrootsList.setListData(empty);
        String[] newArr = new String[temps.size()];
        for(int i=0;i<temps.size();i++)
        {
            newArr[i]=temps.get(i);
        }
        docrootsList.setListData(newArr);
        //appendListData(docrootsList,newArr);                        
    }  
}
 
源代码14 项目: netbeans   文件: NbPlatformCustomizerJavadoc.java
private void addZipFolder(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addZipFolder
    JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastUsedNbPlatformLocation());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileFilter(new FileFilter() {
        public boolean accept(File f)  {
            return f.isDirectory() ||
                    f.getName().toLowerCase(Locale.US).endsWith(".jar") || // NOI18N
                    f.getName().toLowerCase(Locale.US).endsWith(".zip"); // NOI18N
        }
        public String getDescription() {
            return getMessage("CTL_JavadocTab");
        }
    });
    int ret = chooser.showOpenDialog(this);
    if (ret == JFileChooser.APPROVE_OPTION) {
        File javadocRoot = FileUtil.normalizeFile(chooser.getSelectedFile());
        URL newUrl = FileUtil.urlForArchiveOrDir(javadocRoot);
        if (model.containsRoot(newUrl)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                getMessage("MSG_ExistingJavadocRoot")));
        } else {
            ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(javadocRoot.getParentFile().getAbsolutePath());
            model.addJavadocRoot(newUrl);
            javadocList.setSelectedValue(newUrl, true);
        }
    }
    // XXX support adding Javadoc URL too (see java.j2seplatform)
}
 
源代码15 项目: netbeans   文件: PickIconAction.java
protected @Override void performAction(Node[] activatedNodes) {
    FileObject f = PickNameAction.findFile(activatedNodes);
    if (f == null) {
        return;
    }
    NbModuleProvider p = PickNameAction.findProject(f);
    if (p == null) {
        return;
    }
    FileObject src = p.getSourceDirectory();
    JFileChooser chooser = UIUtil.getIconFileChooser();
    chooser.setCurrentDirectory(FileUtil.toFile(src));
    if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    FileObject icon = FileUtil.toFileObject(chooser.getSelectedFile());
    // XXX might instead get WritableXMLFileSystem.cp and search for it in there:
    String iconPath = FileUtil.getRelativePath(src, icon);
    try {
        if (iconPath == null) {
            String folderPath;
            String layerPath = ManifestManager.getInstance(Util.getManifest(p.getManifestFile()), false).getLayer();
            if (layerPath != null) {
                folderPath = layerPath.substring(0, layerPath.lastIndexOf('/'));
            } else {
                folderPath = p.getCodeNameBase().replace('.', '/') + "/resources"; // NOI18N
            }
            FileObject folder = FileUtil.createFolder(src, folderPath);
            FileUtil.copyFile(icon, folder, icon.getName(), icon.getExt());
            iconPath = folderPath + '/' + icon.getNameExt();
        }
        f.setAttribute("iconBase", iconPath); // NOI18N
    } catch (IOException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
}
 
源代码16 项目: Forsythia   文件: GrammarImportExport.java
private File getGrammarFile(){
JFileChooser fc=new JFileChooser();
fc.setCurrentDirectory(getImportExportDir());
int r=fc.showOpenDialog(GE.ge.getUIMain());
if(r!=JFileChooser.APPROVE_OPTION)
  return null;
File selectedfile=fc.getSelectedFile();
importexportdir=fc.getCurrentDirectory();
return selectedfile;}
 
源代码17 项目: whyline   文件: DebugMenu.java
private void generateUsageStatistics() throws IOException {

		String methodname = JOptionPane.showInputDialog(whylineUI, "Which method is the bug in (e.g., \"java/lang/Character.isDefined(C)Z\")?");
		if(methodname == null) return;
		String[] names = methodname.split("\\.");
		
		if(names.length != 2) {
			JOptionPane.showMessageDialog(whylineUI, "Couldn't split into class and method name");
			return;
		}
		Classfile buggyClass = whylineUI.getTrace().getClassfileByName(QualifiedClassName.get(names[0]));
		if(buggyClass == null) {
			JOptionPane.showMessageDialog(whylineUI, "Couldn't find class " + names[0]);
			return;
		}
		MethodInfo buggyMethod = buggyClass.getDeclaredMethodByNameAndDescriptor(names[1]);
		if(buggyMethod == null) {
			JOptionPane.showMessageDialog(whylineUI, "Couldn't find method " + names[1] + " in " + names[0]);
			return;
		}
				
		JFileChooser chooser = new JFileChooser(whylineUI.getTrace().getPath());
		chooser.setDialogTitle("Select a folder that contains the usage logs to analyze");
		chooser.setFileHidingEnabled(true);
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

		int choice = chooser.showOpenDialog(whylineUI);
		
		if(choice != JFileChooser.APPROVE_OPTION) return;
		
		File folder = chooser.getSelectedFile();

		Usage usage = new Usage(whylineUI.getTrace(), folder, buggyMethod);

		JOptionPane.showMessageDialog(whylineUI, "Saved 'results.csv' in " + folder.getName());

	}
 
源代码18 项目: zxpoly   文件: MainForm.java
private void menuFileLoadPokeActionPerformed(ActionEvent evt) {
  stepSemaphor.lock();
  try {
    this.turnZxKeyboardOff();

    final JFileChooser trainerFileChooser = new JFileChooser(this.lastPokeFileFolder);
    trainerFileChooser.setDialogTitle("Select trainer");
    trainerFileChooser.setMultiSelectionEnabled(false);
    trainerFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    trainerFileChooser.setAcceptAllFileFilterUsed(false);
    final FileFilter pokTrainer = new TrainerPok();
    trainerFileChooser.addChoosableFileFilter(pokTrainer);

    if (trainerFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      final AbstractTrainer selectedTrainer =
          (AbstractTrainer) trainerFileChooser.getFileFilter();
      final File selectedFile = trainerFileChooser.getSelectedFile();
      this.lastPokeFileFolder = selectedFile.getParentFile();
      try {
        selectedTrainer.apply(this, selectedFile, this.board);
      } catch (Exception ex) {
        LOGGER.log(Level.WARNING, "Error during trainer processing: " + ex.getMessage(), ex);
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Can't read or parse file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  } finally {
    this.turnZxKeyboardOn();
    stepSemaphor.unlock();
  }
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: MetalworksFrame.java
public void openDocument() {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpenDialog(this);
}
 
源代码20 项目: scava   文件: Main.java
public static void main(String[] args) {

		Vector<Target> targets = new Vector<Target>();

		Target m2mTarget = new Target();
		m2mTarget.setName(M2M);
		Target m2tTarget = new Target();
		m2tTarget.setName(M2T);
		Target setupTarget = new Target();
		setupTarget.setName(SETUP);

		File buildFile = new File(BUILD_XML);
		Project p = new Project();
		p.setUserProperty(ANT_FILE, buildFile.getAbsolutePath());
		p.init();
		ProjectHelper helper = ProjectHelper.getProjectHelper();
		p.addReference(ANT_PROJECT_HELPER, helper);
		helper.parse(p, buildFile);

		Scanner scanner = new Scanner(System.in);
		while (true){
			System.out.println("Which transformation would you like to start? (M2M / M2T) : ");
			String target = scanner.next();
			if (target.equals(M2M)){
				System.out.println("Select the OpenAPI JSON schema to transform.");
				try {
					TimeUnit.MILLISECONDS.sleep(500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				JFileChooser chooser = new JFileChooser();
				chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
				chooser.setCurrentDirectory(new File(SCHEMAS_DIR));
				
				chooser.showOpenDialog(null);
				File selectedFile = chooser.getSelectedFile();
				if (selectedFile.isFile() && selectedFile.getName().endsWith(".json")){
					System.out.println(selectedFile.getName());
					
					targets.add(m2mTarget);
					break;
				} else {
					chooser = null;
					System.out.println("Something went wrong");
				}
				//p.executeSortedTargets(targets);
			} else if (target.equals(M2M)){
				//p.executeTarget(p.getDefaultTarget());
				break;
			} else { 
				System.out.println("Invalid");
			}

		}
		scanner.close();

	}