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


Java JFileChooser类代码示例

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


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

示例1: openFile

import javax.swing.JFileChooser; //导入依赖的package包/类
/**
* 
* @Title: openFile 
* @Description: open file to get file content 
* @param @param parent
* @param @param fc
* @param @return 
* @return String
* @throws
 */
public static String openFile(Component parent, JFileChooser fc)
{
    String content = StringUtils.EMPTY;
    int retVal = fc.showOpenDialog(parent);
    if (JFileChooser.APPROVE_OPTION != retVal)
    {
        return content;
    }

    try
    {
        File sf = fc.getSelectedFile();
        content = FileUtils.readFileToString(sf, Charsets.UTF_8.getCname());
    }
    catch(IOException e)
    {
        FormatView.getView().getStat().setText("Failed to read file: " + e.getMessage());
    }

    return content;
}
 
开发者ID:wisdomtool,项目名称:formatter,代码行数:32,代码来源:FormatUtil.java

示例2: onOpen

import javax.swing.JFileChooser; //导入依赖的package包/类
private void onOpen() {
    File file = selectFile(JFileChooser.OPEN_DIALOG, NbBundle.getMessage(TemplateSelector.class, "CTL_Load")); // NOI18N
    if (file == null) {
        return;
    }

    try {
        byte[] bytes = getFileContentsAsByteArray(file);
        if (bytes != null) {
            getPanel().templateTextArea.setText(new String(bytes));
        }
    } catch (IOException ex) {
        Utils.logError(TemplatesPanel.class, ex);
    }
    preferences.put(KEY_TEMPLATE_FILE, file.getAbsolutePath());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TemplateSelector.java

示例3: browseForImage

import javax.swing.JFileChooser; //导入依赖的package包/类
/**
 * Browse for a particle image and set the value into both the emitter and text field
 * on successful completion
 */
private void browseForImage() {
	if (emitter != null) {
		int resp = chooser.showOpenDialog(this);
		if (resp == JFileChooser.APPROVE_OPTION) {
			File file = chooser.getSelectedFile();
			String path = file.getParentFile().getAbsolutePath();
			String name = file.getName();
			
			ConfigurableEmitter.setRelativePath(path);
			emitter.setImageName(name);
			
			imageName.setText(name);
		}
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:20,代码来源:SettingsPanel.java

示例4: btnDirectoryActionPerformed

import javax.swing.JFileChooser; //导入依赖的package包/类
private void btnDirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDirectoryActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select alternate directory");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String path = txtDirectory.getText();
    if (path == null || path.trim().length() == 0) {
        path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N
    }
    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();
        txtDirectory.setText(projectDir.getAbsolutePath());
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:SettingsPanel.java

示例5: actionPerformed

import javax.swing.JFileChooser; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = GrooveFileChooser.getInstance();
    int result = chooser.showOpenDialog(SaveLTSAsDialog.this.simulator.getFrame());
    // now load, if so required
    if (result == JFileChooser.APPROVE_OPTION) {
        SaveLTSAsDialog.this.dirField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
    if (result == JFileChooser.CANCEL_OPTION) {
        // System.out.println("Cancelled");
    }
    if (result == JFileChooser.ERROR_OPTION) {
        // System.out.println("Whooops");
    }

}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:17,代码来源:SaveLTSAsDialog.java

示例6: promptForFile

import javax.swing.JFileChooser; //导入依赖的package包/类
/**
 * Creates a {@link JFileChooser} dialog prompting the user to select a directory or .pta file.
 * <p>
 * If a directory or .pta file is selected its details are displayed in the UI, otherwise the application is
 * terminated.
 */
private static void promptForFile() {
	// Hide the UI.
	frame.setVisible(false);

	// Prompt the user for a directory/file.
	int result = fileChooser.showDialog(frame, FILE_SELECT_LABEl);
	if (result == JFileChooser.APPROVE_OPTION) {
		// If a directory/file is chosen display its details.
		File selectedFile = fileChooser.getSelectedFile();
		if (selectedFile.isDirectory()) {
			displayDirectory(selectedFile);
		} else {
			displayArchive(selectedFile);
		}
	} else {
		// Otherwise terminate the application.
		System.exit(0);
	}
}
 
开发者ID:Aelexe,项目名称:plain-text-archiver,代码行数:26,代码来源:UserInterface.java

示例7: doLoadGroundTruthFromTXT

import javax.swing.JFileChooser; //导入依赖的package包/类
synchronized public void doLoadGroundTruthFromTXT() {
    JFileChooser c = new JFileChooser(gtFilename);
    c.setDialogTitle("Choose ground truth bounding box file");
    FileFilter filt = new FileNameExtensionFilter("TXT File", "txt");
    c.addChoosableFileFilter(filt);
    c.setFileFilter(filt);
    c.setSelectedFile(new File(gtFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    gtFilename = c.getSelectedFile().toString();
    putString("GTFilename", gtFilename);
    gtFilenameShort = gtFilename.substring(0, 5) + "..." + gtFilename.substring(gtFilename.lastIndexOf(File.separator));
    try {
        this.loadBoundingBoxes(c.getSelectedFile());
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't read bounding box file" + ex + ". See console for logging.", "Bad bounding box file", JOptionPane.WARNING_MESSAGE);
    }

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

示例8: doSaveCalibration

import javax.swing.JFileChooser; //导入依赖的package包/类
synchronized public void doSaveCalibration() {
	if (!calibrated) {
		JOptionPane.showMessageDialog(null, "No calibration yet");
		return;
	}
	JFileChooser j = new JFileChooser();
	j.setCurrentDirectory(new File(dirPath));
	j.setApproveButtonText("Select folder");
	j.setDialogTitle("Select a folder to store calibration XML files");
	j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
	int ret = j.showSaveDialog(null);
	if (ret != JFileChooser.APPROVE_OPTION) {
		return;
	}
	dirPath = j.getSelectedFile().getPath();
	putString("dirPath", dirPath);
	serializeMat(dirPath, "cameraMatrix", cameraMatrix);
	serializeMat(dirPath, "distortionCoefs", distortionCoefs);
	saved = true;
	generateCalibrationString();
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:22,代码来源:StereoCalibrationDualViewFilter.java

示例9: 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

示例10: loadLevel

import javax.swing.JFileChooser; //导入依赖的package包/类
private void loadLevel()
{
    JFileChooser chooser = new JFileChooser(lastDir == null ? PathHelper.getDialogDirIfFound() : lastDir);
    chooser.addChoosableFileFilter(filter);
    chooser.setAcceptAllFileFilterUsed(true);
    chooser.setMultiSelectionEnabled(false);

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION)
    {
        saveButton.setEnabled(false);
        replaceView(createLevelPanel);
        level = null;
        File selectedFile = chooser.getSelectedFile();
        try {
            level = DialogDataHelper.getDialogRoot(selectedFile);
            lastDir = selectedFile.getParentFile();
            saveButton.setEnabled(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Beim Laden ist ein Fehler aufgetreten!\n" + e.getMessage(), "Fehler!", JOptionPane.OK_OPTION);
        }
        rebuildTree();
    }
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:26,代码来源:DialogEditor.java

示例11: selectDirectory

import javax.swing.JFileChooser; //导入依赖的package包/类
public static String selectDirectory(Component component, String choosertitle)
{
	JFileChooser chooser = new JFileChooser(); 
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle(choosertitle);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    
    if (chooser.showOpenDialog(component) == JFileChooser.APPROVE_OPTION) { 
      System.out.println("getCurrentDirectory(): "  +  chooser.getCurrentDirectory());
      System.out.println("getSelectedFile() : "  +  chooser.getSelectedFile());
      return chooser.getSelectedFile().toString();
      }
    else {
      System.out.println("No Selection ");
      return null;
      }
    
}
 
开发者ID:fossasia,项目名称:zooracle,代码行数:20,代码来源:FileUtils.java

示例12: prepareFileChooser

import javax.swing.JFileChooser; //导入依赖的package包/类
/**
 * Creates and initializes a file chooser.
 *
 * @return  the initialized file chooser
 */
protected JFileChooser prepareFileChooser() {
    FileChooserBuilder fcb = new FileChooserBuilder(OpenFileAction.class);
    fcb.setSelectionApprover(new OpenFileSelectionApprover());
    fcb.setFilesOnly(true);
    fcb.addDefaultFileFilters();
    for (OpenFileDialogFilter filter :
            Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
        fcb.addFileFilter(filter);
    }
    JFileChooser chooser = fcb.createFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.getCurrentDirectory().listFiles(); //preload
    chooser.setCurrentDirectory(getCurrentDirectory());
    if (currentFileFilter != null) {
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            if (currentFileFilter.equals(ff.getDescription())) {
                chooser.setFileFilter(ff);
                break;
            }
        }
    }
    HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
    return chooser;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:OpenFileAction.java

示例13: buttonWorkDirActionPerformed

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

示例14: nativeIconButtonActionPerformed

import javax.swing.JFileChooser; //导入依赖的package包/类
private void nativeIconButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nativeIconButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new IconFileFilter(false));
    String current = nativeIconTextField.getText();
    File lastFolder = current!=null ? getFileFromPath(current) : null;
    if (lastFolder != null) {
        chooser.setSelectedFile(lastFolder);
    } else if (lastImageFolder != null) {
        chooser.setSelectedFile(lastImageFolder);
    } else { // ???
        // workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
        // chooser.setSelectedFile(new File(workDir));
    }
    chooser.setDialogTitle(NbBundle.getMessage(JFXIconsPanel.class, "LBL_Select_Icon_Image")); // NOI18N
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        String relPath = JFXProjectUtils.getRelativePath(project.getProjectDirectory(), FileUtil.toFileObject(file));
        nativeIconTextField.setText(relPath);
        lastImageFolder = file;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:JFXIconsPanel.java

示例15: importPreferencesDialog

import javax.swing.JFileChooser; //导入依赖的package包/类
/**
 * Shows a file dialog from which to import preferences for biases from the
 * tree.
 */
public void importPreferencesDialog() {
    JFileChooser chooser = new JFileChooser();
    XMLFileFilter filter = new XmlAedatFileFilter();
    
    String lastFilePath = prefs.get("BiasgenFrame.lastFile", defaultFolder);
    lastFile = new File(lastFilePath);
    chooser.setFileFilter(filter);
    chooser.setCurrentDirectory(lastFile);
    int retValue = chooser.showOpenDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        try {
            lastFile = chooser.getSelectedFile();
            importPreferencesFromFile(lastFile);
        } catch (Exception fnf) {
            log.warning(fnf.toString());
        }
    }
    //        resend(); // shouldn't be necessary with the batch edit start/end in biasgen.importPreferences
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:24,代码来源:BiasgenFrame.java


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