Java 8 JFileChooser - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JFileChooser class.

This code example shows how to use the following methods:getCurrentDirectory, getSelectedFile, setCurrentDirectory, showOpenDialog, showSaveDialog
	} 
 
	@Override 
	public void actionPerformed(ActionEvent arg0) {
		int rv;
		jfc.setCurrentDirectory(defaultDir.val);
		if(isOpen)
			rv = jfc.showOpenDialog(parent);
		else 
			rv = jfc.showSaveDialog(parent);
		 
		if(rv == JFileChooser.APPROVE_OPTION) {
			File f = jfc.getSelectedFile();
			 
			try { 
				textbox.setText(f.getCanonicalPath());
			} catch(IOException e) {
				textbox.setText(f.getAbsolutePath());
			} 
		} 

7
CodeRank
This code example shows how to use the following methods:getSelectedFile, showOpenDialog
This code example shows how to use the following methods:getSelectedFile, setFileSelectionMode, showSaveDialog
 
	@Override 
	protected void doExecute(Application app) {
		File imageDirectory = app.getSettings().getImageDirectory();
 
		final JFileChooser chooser = new JFileChooser(imageDirectory);
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int rc = chooser.showSaveDialog(app.getAppFrame());
		if (rc != JFileChooser.APPROVE_OPTION)
			return; 
 
		imageDirectory = chooser.getSelectedFile();
		if (!(imageDirectory.isAbsolute() && imageDirectory.canWrite())) {
			JOptionPane.showMessageDialog(app.getAppFrame(), "Not a writable directory '" + imageDirectory + "'", "Invalid directory", JOptionPane.ERROR_MESSAGE);
			return; 
		} 
 
		app.getSettings().setImageDirectory(imageDirectory);
		updateView(imageDirectory);
	} 
7
CodeRank
This code example shows how to use the following methods:addChoosableFileFilter, getCurrentDirectory, setAcceptAllFileFilterUsed, setCurrentDirectory, setFileFilter
        } 
        else if (lastJFCDirectory == null) {
            String start = System.getProperty("user.dir", ""); //$NON-NLS-1$//$NON-NLS-2$
 
            if (start.length() > 0) {
                jfc.setCurrentDirectory(new File(start));
            } 
        } 
        clearFileFilters(); 
        if(exts != null && exts.length > 0) {
            JMeterFileFilter currentFilter = new JMeterFileFilter(exts);
            jfc.addChoosableFileFilter(currentFilter);
            jfc.setAcceptAllFileFilterUsed(true);
            jfc.setFileFilter(currentFilter);
        } 
        if(lastJFCDirectory==null) {
            lastJFCDirectory = System.getProperty("user.dir", ""); //$NON-NLS-1$//$NON-NLS-2$
        } 
        jfc.setCurrentDirectory(new File(lastJFCDirectory));
        int retVal = jfc.showOpenDialog(GuiPackage.getInstance().getMainFrame());

7
CodeRank
This code example shows how to use the following methods:getSelectedFile, setFileFilter, showOpenDialog, showSaveDialog
 
	/** 
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 
	 */ 
	public void actionPerformed(ActionEvent evt) {
		JFileChooser fc = new JFileChooser();
		if (filter != null) {
			fc.setFileFilter(filter);
		} 
		int okCancel;
		if (newFile) {
			okCancel = fc.showSaveDialog(null);
		} 
		else { 
			okCancel = fc.showOpenDialog(null);
		} 
		if (okCancel == JFileChooser.APPROVE_OPTION) {
			file = fc.getSelectedFile();
			observable.notifyObservers(this);
		} 

7
CodeRank
This code example shows how to use the following methods:getFileFilter, getSelectedFile, setAcceptAllFileFilterUsed, setDialogTitle, setDialogType
     * Present a file chooser dialog for loading a Graph or Tree data set. 
     * @param c user interface component from which the request is being made 
     * @return a newly loaded Graph, or null if not found or action canceled 
     */ 
    public static Graph getGraphFile(Component c) {
        JFileChooser jfc = new JFileChooser();
        jfc.setDialogType(JFileChooser.OPEN_DIALOG);
        jfc.setDialogTitle("Open Graph or Tree File");
        jfc.setAcceptAllFileFilterUsed(false);
         
        SimpleFileFilter ff;
         
        // TODO: have this generate automatically 
        // tie into PrefuseConfig?? 
 
        // TreeML 
        ff = new SimpleFileFilter("xml",
                "TreeML File (*.xml, *.treeml)", 
                new TreeMLReader()); 
        ff.addExtension("treeml");

7
CodeRank
This code example shows how to use the following methods:addChoosableFileFilter, setCurrentDirectory, setMultiSelectionEnabled
     * Creates the file chooser. 
     * 
     * @return the initialized file chooser. 
     */ 
    protected JFileChooser createFileChooser() {
        final JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(
            new ExtensionFileFilter(getFileDescription(), getFileExtension()) 
        ); 
        fc.setMultiSelectionEnabled(false);
        fc.setCurrentDirectory(getCurrentDirectory());
        return fc;
    } 
     
} 
7
CodeRank
This code example shows how to use the following methods:addActionListener, setApproveButtonText, setApproveButtonToolTipText, setCurrentDirectory, setFileSelectionMode
	 * @param directory The default directory. 
	 */ 
	private void initComponents(String directory)
	{ 
		setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
		chooser = new JFileChooser();
		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		if (directory != null && directory.length() > 0)
			chooser.setCurrentDirectory(new File(directory));
		chooser.setApproveButtonText("Open");
		chooser.setApproveButtonToolTipText("Open the document with the " +
				"selected application"); 
		chooser.addActionListener(this);
	} 
	 
	/** 
	 * Builds and lays out the UI. 
	 *  
	 * @param name The name of the document to open. 
	 */ 
7
CodeRank
This code example shows how to use the following methods:getSelectedFile, setAcceptAllFileFilterUsed, setCurrentDirectory, setDialogTitle, setFileSelectionMode
	} 
	public static final long serialVersionUID = 0l;
	// This method is called when the button is pressed 
	public void actionPerformed(ActionEvent evt) {
		// Perform action... 
		JFileChooser chooser = new JFileChooser();
		String txt = textField.getText();
		 
		if ( config == null) {
			System.out.println("config == null, calling getWebStartConfig...");
			config = WebStartMain.getWebStartConfig();
		} 
		if ( txt != null){
			chooser.setCurrentDirectory(new java.io.File(txt));
			config.setPdbFilePath(txt);
			try { 
				PersistentConfig webstartConfig = new PersistentConfig();
 
				webstartConfig.save(config);
 

6
CodeRank
This code example shows how to use the following methods:getSelectedFile, showSaveDialog
    appletPanel.add(lPercentDone);  
     
     
    //Initialize parameters 
    url = this.getParameter("torrentUrl");
    JFileChooser fileChooser = new JFileChooser();
    int result = fileChooser.showSaveDialog(this);
    if(result == JFileChooser.APPROVE_OPTION)
      savePath =  fileChooser.getSelectedFile().getName();
       
    System.out.println(url + "\n" + savePath);   
       
     
    this.add(appletPanel);
    this.setSize(200,100);
  } 
   
   
 
} 
6
CodeRank
See Code Examples for Java 8 JFileChooser Methods: