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

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

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select Project Location");
        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();
    }

}
 
源代码2 项目: chipster   文件: SwingClientApplication.java
/**
 * Opens JFileChooser to ask location for the export, then calls
 * exportDataDirectory to do the job.
 * 
 * @param data
 * @throws MicroarrayException
 * @throws IOException
 */
public void exportFolder(DataFolder data) throws MicroarrayException, IOException {

	File file = new File(data.getName().replace(" ", "_"));
	// file.mkdirs();

	JFileChooser fc = getImportExportDirChooser();
	fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	fc.setSelectedFile(file);

	logger.debug("Exporting File: " + fc.getSelectedFile().getAbsolutePath());

	int ret = fc.showSaveDialog(getMainFrame());

	if (ret == JFileChooser.APPROVE_OPTION) {
		File selected = new File(fc.getSelectedFile().getAbsolutePath() + File.separator + file.getName());
		selected.mkdirs();
		exportDataFolder(data, selected);
	}
}
 
源代码3 项目: netbeans   文件: CustomizerRun.java
private void jButtonWorkingDirectoryBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    
    String workDir = jTextWorkingDirectory.getText();
    if (workDir.equals("")) {
        workDir = FileUtil.toFile(uiProperties.getProject().getProjectDirectory()).getAbsolutePath();
    }
    chooser.setSelectedFile(new File(workDir));
    chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        jTextWorkingDirectory.setText(file.getAbsolutePath());
    }
}
 
源代码4 项目: netbeans   文件: PanelProjectLocationVisual.java
private void browseLocationJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationJButtonActionPerformed
            JFileChooser chooser = new JFileChooser ();
            FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
            chooser.setDialogTitle(NbBundle.getMessage(PanelProjectLocationVisual.class,"GetProjectLocationPanel.FileChooserTitle"));
            chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
            String path = projectLocationTextField.getText().trim();
            if (path.length() > 0) {
                File f = new File (path);
                if (f.exists ()) {
                    chooser.setSelectedFile(f);
                }
            }
            if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this))) { //NOI18N
                File projectDir = chooser.getSelectedFile();
                projectLocationTextField.setText( projectDir.getAbsolutePath() );
            }   
}
 
源代码5 项目: netbeans   文件: NBProjectGeneratorsPanelVisual.java
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
        chooser.setDialogTitle("Select Project Location");
        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();
    }

}
 
源代码6 项目: xdm   文件: MainWindow.java
private void changeFile(String id) {
	DownloadEntry ent = XDMApp.getInstance().getEntry(id);
	if (ent == null)
		return;
	if (ent.getState() == XDMConstants.FINISHED) {
		return;
	}
	JFileChooser jfc = new JFileChooser();
	jfc.setSelectedFile(
			new File(XDMApp.getInstance().getOutputFolder(id), XDMApp.getInstance().getOutputFile(id, false)));
	if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
		File f = jfc.getSelectedFile();
		ent.setFolder(f.getParent());
		ent.setFile(f.getName());
		XDMApp.getInstance().fileNameChanged(id);
	}
}
 
源代码7 项目: netbeans   文件: RemoteRepository.java
private void onBrowse() {
    String path = settingsPanel.txtIdentityFile.getText();
    if (path.isEmpty()) {
        path = getDefaultIdentityFilePath();
    }
    File file = new File(path);
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(RemoteRepositoryPanel.class, "RepositoryPanel.IdentityFile.FileChooser.Descritpion"), //NOI18N
            path.isEmpty() ? null : file.getParentFile());
    if (!path.isEmpty()) {
        fileChooser.setSelectedFile(file);
    }
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setDialogTitle(NbBundle.getMessage(RemoteRepositoryPanel.class, "RepositoryPanel.IdentityFile.FileChooser.Title")); //NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showDialog(panel, null)) {
        File f = fileChooser.getSelectedFile();
        settingsPanel.txtIdentityFile.setText(f.getAbsolutePath());
    }
}
 
源代码8 项目: Ngram-Graphs   文件: MainINSECTForm.java
private void DataDirEdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DataDirEdActionPerformed
    // Select a dir
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory((DataDirEd.getText().length() == 0) ? new java.io.File(".") : new java.io.File(DataDirEd.getText()));
    fc.setSelectedFile(fc.getCurrentDirectory());
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int iRet = fc.showOpenDialog(this);
    if (iRet == JFileChooser.APPROVE_OPTION)
    {
        DataDirEd.setText(fc.getSelectedFile().getAbsolutePath());
        
        // Get categories from disk
        INSECTFileDB fdData= new INSECTFileDB("", DataDirEd.getText());
        Iterator iIter = Arrays.asList(fdData.getObjectList(INSECTMemoryDB.CATEGORY_TYPE)).iterator();
        while (iIter.hasNext()) {
            String sObjectName = (String)iIter.next();
            DataRepository.saveObject((NamedDocumentNGramGraph)fdData.loadObject(sObjectName,
                    INSECTMemoryDB.CATEGORY_TYPE), sObjectName, INSECTMemoryDB.CATEGORY_TYPE);
        }
        // Inform Categorizer
        CategoryDecider.setRepository(DataRepository);
        
        UpdateCategoriesByUIValues();
    }
}
 
源代码9 项目: netbeans   文件: ProjectProblemsProviders.java
@Override
@NonNull
@NbBundle.Messages({
    "LBL_BrokenLinksCustomizer_Resolve_File=Browse \"{0}\""
})
public Future<ProjectProblemsProvider.Result> resolve() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setDialogTitle(LBL_BrokenLinksCustomizer_Resolve_File(getDisplayId(type, id)));
    if (lastSelectedFile != null) {
        chooser.setSelectedFile(lastSelectedFile);
    }
    int option = chooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        updateReference(chooser.getSelectedFile());
        lastSelectedFile = chooser.getSelectedFile();
        resolved = ProjectProblemsProvider.Status.RESOLVED;
    }
    return new Done(ProjectProblemsProvider.Result.create(resolved));
}
 
源代码10 项目: netbeans   文件: AddServerLocationVisualPanel.java
private JFileChooser getJFileChooser() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
    chooser.setMultiSelectionEnabled(false);
    chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N

    chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N

    // set the current directory
    chooser.setSelectedFile(new File(locationTextField.getText().trim()));

    return chooser;
}
 
源代码11 项目: netbeans   文件: BasicProjectInfoPanel.java
private void browseProjectLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseProjectLocationActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
        chooser.setSelectedFile(getProjectLocation());
    } else {
        chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
    }
    chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Location"));  //NOI18N
    if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File projectLoc = FileUtil.normalizeFile(chooser.getSelectedFile());
        projectLocation.setText(projectLoc.getAbsolutePath());
    }
}
 
源代码12 项目: raccoon4   文件: SaveAction.java
@Override
public void actionPerformed(ActionEvent e) {
	if (globals.get(Traits.class).isAvailable("4.0.x")) {
		JFileChooser jfc = new JFileChooser();
		String fn = MessageFormat.format(
				Messages.getString("SaveAction.filename"), seq);
		jfc.setSelectedFile(new File(dir, fn));
		FileNameExtensionFilter fileFilter = new FileNameExtensionFilter(
				Messages.getString("SaveAction.types"), "png");
		jfc.setFileFilter(fileFilter);
		jfc.setFileFilter(new FileNameExtensionFilter(Messages
				.getString("SaveAction.filetype"), "png"));
		int ret = jfc.showSaveDialog(panel);
		if (ret == JFileChooser.APPROVE_OPTION) {
			try {
				ImageIO.write(panel.getImage(), "png", jfc.getSelectedFile());
				seq++;
			}
			catch (Exception exp) {
				exp.printStackTrace();
			}
		}
	}
	else {
		globals.get(LifecycleManager.class).sendBusMessage(new JTextField());
	}
}
 
源代码13 项目: amidst   文件: BiomeExporterDialog.java
private Path getExportPath() {
	Path file = null;

	JFileChooser fileChooser = new JFileChooser();
	fileChooser.setFileFilter(new PNGFileFilter());
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setSelectedFile(Paths.get(pathField.getText()).toAbsolutePath().toFile());
	if (fileChooser.showDialog(dialog, "Confirm") == JFileChooser.APPROVE_OPTION) {
		file = Actions.appendFileExtensionIfNecessary(fileChooser.getSelectedFile().toPath(), "png");
	}

	return file;
}
 
源代码14 项目: chipster   文件: RemoteSessionChooserFactory.java
public JFileChooser getExampleSessionChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {
	JFileChooser exampleSessionFileChooser = populateFileChooserFromServer(false);
	exampleSessionFileChooser.setSelectedFile(new File("session"));
	ServerFileUtils.hideJFileChooserButtons(exampleSessionFileChooser);
	exampleSessionFileChooser.setPreferredSize(new Dimension(800, 600));

	ServerFileSystemView view = (ServerFileSystemView) exampleSessionFileChooser.getFileSystemView();
	exampleSessionFileChooser.setCurrentDirectory(view.getExampleSessionDir());				
	
	return exampleSessionFileChooser;
}
 
源代码15 项目: snap-desktop   文件: MaskFormActions.java
private void exportSelectedMasks() {
    final Mask[] masks = getMaskForm().getSelectedMasks();
    if (masks.length == 0) {
        return;
    }

    Document document = new Document(new Element(DimapProductConstants.TAG_MASKS));
    boolean[] masksExported = addContent(masks, document);
    boolean dialogApproved = false;
    if (hasAtLeastOneMaskExported(masksExported)) {
        final JFileChooser fileChooser = new SnapFileChooser();
        fileChooser.setDialogTitle(ACTION_NAME);
        final FileFilter fileFilter = new SnapFileFilter("XML", ".xml", "XML files (*.xml)");
        fileChooser.setFileFilter(fileFilter);
        final File targetDirectory = getDirectory();
        fileChooser.setCurrentDirectory(targetDirectory);
        fileChooser.setSelectedFile(new File(targetDirectory, masks[0].getName()));
        final int result = fileChooser.showSaveDialog(SwingUtilities.getWindowAncestor(maskTopComponent));
        dialogApproved = result == JFileChooser.APPROVE_OPTION;
        if (dialogApproved) {
            File file = fileChooser.getSelectedFile();
            if (file != null) {
                if (Boolean.TRUE.equals(Dialogs.requestOverwriteDecision(ACTION_NAME, file))) {
                    setDirectory(file.getAbsoluteFile().getParentFile());
                    file = FileUtils.ensureExtension(file, ".xml");
                    writeXml(file, document);
                }
            }
        }
    }
    boolean allExportsFailed = countFailedMasks(masksExported) == masksExported.length;
    if (dialogApproved || allExportsFailed) {
        showUserFeedback(masks, masksExported);
    }
}
 
源代码16 项目: netbeans   文件: InstallPanelVisual.java
private void jButtonHomeBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonHomeBrowseActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setSelectedFile(new File(jTextFieldHomeDir.getText().trim()));
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        jTextFieldHomeDir.setText(chooser.getSelectedFile().getAbsolutePath());
        fireChange();
    }
}
 
源代码17 项目: Compressor   文件: ZipDialog.java
private void onCompressFile(Compressor c) {
	File f = getSelectedArchiverFile(null);
	if (f == null) {
		return;
	}
	FileNameExtensionFilter filter = c.getFileFilter();
	String ext = "." + filter.getExtensions()[0];
	String destpath = f.getName() + ext;
	JFileChooser s = new JFileChooser(".");
	s.addChoosableFileFilter(filter);
	s.setSelectedFile(new File(destpath));
	int returnVal = s.showSaveDialog(this);
	if (returnVal != JFileChooser.APPROVE_OPTION) {
		return;
	}
	File ff = s.getSelectedFile();
	destpath = ff.getAbsolutePath();
	if (!filter.accept(ff)) {// 确保一定有后缀
		destpath += ext;
	}

	try {
		c.doCompress(f, destpath);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
源代码18 项目: visualvm   文件: SnapshotsSupport.java
/**
 * Saves the snapshot to a used-defined file (opens Save File dialog with defined caption).
 * 
 * @param snapshot Snapshot to be saved.
 * @param dialogTitle Save File dialog caption.
 */
public void saveAs(final Snapshot snapshot, String dialogTitle) {
    final File file = snapshot.getFile();
    if (file == null) {
        ProfilerDialogs.displayError(NbBundle.getMessage(SnapshotsSupport.class, "LBL_CannotSave"));  // NOI18N
    } else {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(dialogTitle);
        chooser.setSelectedFile(new File(snapshot.getFile().getName()));
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setFileFilter(snapshot.getCategory().getFileFilter());
//        chooser.setFileView(category.getFileView());
        if (chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) {
            String categorySuffix = snapshot.getCategory().getSuffix();
            String filePath = chooser.getSelectedFile().getAbsolutePath();
            if (!filePath.endsWith(categorySuffix)) filePath += categorySuffix;
            final File copy = new File(filePath);
            VisualVM.getInstance().runTask(new Runnable() {
                public void run() {
                    ProgressHandle pHandle = null;
                    try {
                        pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(SnapshotsSupport.class, "LBL_Saving",DataSourceDescriptorFactory.getDescriptor(snapshot).getName()));  // NOI18N
                        pHandle.setInitialDelay(0);
                        pHandle.start();
                        Utils.copyFile(file, copy);
                    } finally {
                        final ProgressHandle pHandleF = pHandle;
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() { if (pHandleF != null) pHandleF.finish(); }
                        });
                    }
                }
            });
        }
    }
}
 
源代码19 项目: netbeans   文件: DerbyPropertiesPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(null);
        chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
        String location = getInstallLocation();
        if (location.length() > 0) {
            chooser.setSelectedFile(new File(location));
        } else {
            chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); // NOI18N
        }
        if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        setInstallLocation(chooser.getSelectedFile().getAbsolutePath());
}
 
源代码20 项目: Ngram-Graphs   文件: AutoSummENGGui.java
/** Select the directory of the model summaries. */
private void BrowseModelDirBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseModelDirBtnActionPerformed
    // Select a dir
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory((ModelsRootDirEdt.getText().length() == 0) ? 
        new java.io.File(".") : new java.io.File(ModelsRootDirEdt.getText()));
    fc.setSelectedFile(fc.getCurrentDirectory());
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int iRet = fc.showOpenDialog(this);
    if (iRet == JFileChooser.APPROVE_OPTION)
    {
        ModelsRootDirEdt.setText(fc.getSelectedFile().getAbsolutePath());
    }
}