Java JFileChooser setSelectedFile(JFileChooser chooser, File file)

Here you can find the source of setSelectedFile(JFileChooser chooser, File file)

Description

Set starting dir and file for a chooser.

License

Apache License

Parameter

Parameter Description
chooser a parameter
file a parameter

Declaration

public static void setSelectedFile(JFileChooser chooser, File file) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    /**//from   w  ww . j av  a  2s.  c om
     * Set starting dir and file for a chooser.
     * chooser.setSelectedFile doesn't work correctly when given a directory.
     *
     * @param chooser
     * @param file
     */
    public static void setSelectedFile(JFileChooser chooser, File file) {
        if (file.isDirectory())
            chooser.setCurrentDirectory(file);
        else
            chooser.setSelectedFile(file);
    }
}

Related

  1. selectFileForOpen(final Component parent, final FileFilter[] fileFilters, final String title, final FileFilter[] selectedFilters, final File initFile)
  2. selectNonExistingFile(Component parent, String extensionWanted)
  3. setCurrentDirectory(JFileChooser fileChooser, String location)
  4. setFile(File file, JFileChooser chooser)
  5. setFileChooserFilters(JFileChooser fileDlg, String filters, int selectIndex)
  6. SHOW_JFILECHOOSER(String title, String approvetext, int fileselectionmode, boolean multiselection)
  7. showFileChooserLoop(Component parentComponent, JFileChooser chooser)
  8. write(File file, String text)
  9. writeOnFile(String row)