当前位置: 首页>>代码示例>>Java>>正文


Java JFileChooser.setSelectedFile方法代码示例

本文整理汇总了Java中javax.swing.JFileChooser.setSelectedFile方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.setSelectedFile方法的具体用法?Java JFileChooser.setSelectedFile怎么用?Java JFileChooser.setSelectedFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JFileChooser的用法示例。


在下文中一共展示了JFileChooser.setSelectedFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invokeFileSelector

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void invokeFileSelector(JTextField path) {
    File f = new File(path.getText());

    while (f != null && f.toPath() != null && f.toPath().getNameCount() > 0 && !f.exists()) {
        f = f.getParentFile();
    }

    JFileChooser fc = new JFileChooser();

    if (f != null) {
        fc.setSelectedFile(f);
    }
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int res = fc.showOpenDialog(this);
    if (res == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        path.setText(file.getAbsolutePath());
    }
}
 
开发者ID:nebbian,项目名称:RoboxSlicerExtension,代码行数:22,代码来源:ControlWindow.java

示例2: doSave

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void doSave() {
	MemState s = factory.getState(instance, circState);

	JFileChooser chooser = proj.createChooser();
	File oldSelected = factory.getCurrentImage(instance);
	if (oldSelected != null)
		chooser.setSelectedFile(oldSelected);
	chooser.setDialogTitle(Strings.get("ramSaveDialogTitle"));
	int choice = chooser.showSaveDialog(frame);
	if (choice == JFileChooser.APPROVE_OPTION) {
		File f = chooser.getSelectedFile();
		try {
			HexFile.save(f, s.getContents());
			factory.setCurrentImage(instance, f);
		} catch (IOException e) {
			JOptionPane.showMessageDialog(frame, e.getMessage(), Strings.get("ramSaveErrorTitle"),
					JOptionPane.ERROR_MESSAGE);
		}
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:21,代码来源:MemMenu.java

示例3: browseProjectLocation

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseProjectLocation(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseProjectLocation
    // TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(NbBundle.getMessage(PanelSourceFolders.class, "LBL_NWP1_SelectProjectLocation")); // NOI18N
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    String path = this.projectLocation.getText();
    if (path.length() > 0) {
        File f = new File(path);
        File owner = f.getParentFile();
        if (owner.exists()) {
            chooser.setCurrentDirectory(owner);
        }
        if (f.exists()) {
            chooser.setSelectedFile(f);
        }
    }
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (file != null) {
            this.projectLocation.setText(FileUtil.normalizeFile(file).getAbsolutePath());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:PanelProjectLocationExtSrc.java

示例4: saveAsASCII

import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected void saveAsASCII(Iterator it) {
	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	File f = new File("PDB_Export.txt");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==jfc.CANCEL_OPTION||c==jfc.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		BufferedWriter out = new BufferedWriter(new FileWriter(f));
		for (; it.hasNext(); ) {
			out.write(it.next().toString());
			out.write("\n");
		}
		out.close();
	} catch (IOException ex){}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:25,代码来源:PDB.java

示例5: selectFile

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private File selectFile(int dialogType, String approveButtonText) {
        JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(TemplateSelector.class, "ACSD_SelectTemplate")/*, defaultDir*/);// NOI18N
        fileChooser.setDialogTitle(NbBundle.getMessage(TemplateSelector.class, "CTL_SelectTemplate"));// NOI18N
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setDialogType(dialogType);

        File file = getTemplateFile();

//        if(file.isFile() && dialogType == JFileChooser.OPEN_DIALOG) {
//            fileChooser.setSelectedFile(file);
//        } else {
//            fileChooser.setCurrentDirectory(file.isFile() ? file.getParentFile() : file);
//        }
        if(file.isFile() ) {
            fileChooser.setSelectedFile(file);
        } else {
            fileChooser.setCurrentDirectory(file);
        }

        fileChooser.showDialog(getPanel(), approveButtonText);
        File f = fileChooser.getSelectedFile();
        return f;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:TemplateSelector.java

示例6: doLoadApsDvsNetworkFromXML

import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
 * Loads a convolutional neural network (CNN) trained using DeapLearnToolbox
 * for Matlab (https://github.com/rasmusbergpalm/DeepLearnToolbox) that was
 * exported using Danny Neil's XML Matlab script cnntoxml.m.
 *
 */
synchronized public void doLoadApsDvsNetworkFromXML() {
    JFileChooser c = new JFileChooser(lastApsDvsNetXMLFilename);
    FileFilter filt = new FileNameExtensionFilter("XML File", "xml");
    c.addChoosableFileFilter(filt);
    c.setFileFilter(filt);
    c.setSelectedFile(new File(lastApsDvsNetXMLFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    lastApsDvsNetXMLFilename = c.getSelectedFile().toString();
    putString("lastAPSNetXMLFilename", lastApsDvsNetXMLFilename);
    try {
        apsDvsNet.loadFromXMLFile(c.getSelectedFile());
        dvsSubsampler = new DvsFramerSingleFrame(chip);
        dvsSubsampler.setFromNetwork(apsDvsNet);
    } catch (Exception ex) {
        Logger.getLogger(DavisDeepLearnCnnProcessor_HJ.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't load net from this file, caught exception " + ex + ". See console for logging.", "Bad network file", JOptionPane.WARNING_MESSAGE);
    }

}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:29,代码来源:DavisDeepLearnCnnProcessor_HJ.java

示例7: browseButtonActionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
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();
    }

}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:23,代码来源:ExampleBotProjectPanelVisual.java

示例8: btnWorkDirActionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void btnWorkDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWorkDirActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    
    String workDir = txtWorkDir.getText();
    if (workDir.equals("")) { //NOI18N
        workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
    }
    chooser.setSelectedFile(new File(workDir));
    chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(RunJarPanel.class, "TIT_SelectWorkingDirectory"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        txtWorkDir.setText(file.getAbsolutePath());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:RunJarPanel.java

示例9: resolve

import javax.swing.JFileChooser; //导入方法依赖的package包/类
@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));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ProjectProblemsProviders.java

示例10: doExport

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void doExport(String name, String extension) {
	JFileChooser fc = new FileChooser();
	fc.setDialogTitle("Exporting cuttlefish network to " + name);
	fc.setSelectedFile(new File(getOutputName(extension)));
	fc.setFileFilter(new FileNameExtensionFilter(
			"." + extension + " files", extension));
	if (fc.showSaveDialog(networkPanel) == JFileChooser.APPROVE_OPTION) {

		try {
			Exporter exporter = NetworkExportController
					.getExporter(extension);
			NetworkExportController.export(networkPanel.getNetwork(),
					fc.getSelectedFile(), exporter);
		} catch (Exception ex) {
			errorPopup(ex, "Output error when saving in GraphML!");
		}
	}
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:19,代码来源:ExportMenu.java

示例11: actionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
	if (UIManager.getBoolean("FileChooser.readOnly")) {
		return;
	}
	JFileChooser fc = getFileChooser();
	File currentDirectory = fc.getCurrentDirectory();
	FileSystemView fsv = fc.getFileSystemView();
	File newFolder = null;

	String name = SwingTools.showInputDialog("file_chooser.new_folder", "");

	try {
		if (name != null && !"".equals(name)) {
			newFolder = fsv.createNewFolder(currentDirectory);
			if (newFolder.renameTo(fsv.createFileObject(fsv.getParentDirectory(newFolder), name))) {
				newFolder = fsv.createFileObject(fsv.getParentDirectory(newFolder), name);
			} else {
				SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.rename", name);
			}
		}
	} catch (IOException exc) {
		SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.create", name);
		return;
	} catch (Exception exp) {
		// do nothing
	}

	if (fc.isMultiSelectionEnabled()) {
		fc.setSelectedFiles(new File[] { newFolder });
	} else {
		fc.setSelectedFile(newFolder);
	}

	fc.rescanCurrentDirectory();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:37,代码来源:FileChooserUI.java

示例12: browseProjectLocationActionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
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());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:BasicProjectInfoPanel.java

示例13: brows

import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected void brows() {
    final JFileChooser chooser = getChooser();
    chooser.setSelectedFile(new File(jTextField.getText()));
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        jTextField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:8,代码来源:HTMLEditOptionPanel.java

示例14: saveWorksheetAs

import javax.swing.JFileChooser; //导入方法依赖的package包/类
public void saveWorksheetAs(SimulationFrame frame) {
	if(frame==null)
		return;
	JFileChooser chooser = getFileChooser();
	chooser.setSelectedFile(new File(frame.getFileName()));
	if(chooser.showSaveDialog(Application.this)!=JFileChooser.APPROVE_OPTION)
		return;
	saveWorksheet(desktop.getSelectedFrame(), chooser.getSelectedFile());
}
 
开发者ID:kristian,项目名称:JDigitalSimulator,代码行数:10,代码来源:Application.java

示例15: bUserExtensionFileActionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void bUserExtensionFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUserExtensionFileActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileNameExtensionFilter("Javascript File", "js"));
    chooser.setSelectedFile(new File(tfUserExtensionFile.getText().trim()));
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        tfUserExtensionFile.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Selenium2Customizer.java


注:本文中的javax.swing.JFileChooser.setSelectedFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。