Java JFileChooser setCurrentDirectory(JFileChooser fileChooser, String location)

Here you can find the source of setCurrentDirectory(JFileChooser fileChooser, String location)

Description

set Current Directory

License

Apache License

Declaration

public static void setCurrentDirectory(JFileChooser fileChooser, String location) 

Method Source Code

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

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    public static void setCurrentDirectory(JFileChooser fileChooser, String location) {
        if (pointsToFile(location))
            location = location.substring(0, location.lastIndexOf("\\"));
        File dir = new File(location);
        if (dir.exists())
            fileChooser.setCurrentDirectory(dir);
    }// w  ww  .  ja va 2s  .co m

    private static boolean pointsToFile(String location) {
        if (location.lastIndexOf("\\") < location.lastIndexOf("."))
            return true;
        return false;
    }
}

Related

  1. selectFile(boolean exitOnCancel)
  2. selectFile(Component parent, boolean isOpen)
  3. selectFile(String msg, File dir, FileFilter filterOrNull)
  4. selectFileForOpen(final Component parent, final FileFilter[] fileFilters, final String title, final FileFilter[] selectedFilters, final File initFile)
  5. selectNonExistingFile(Component parent, String extensionWanted)
  6. setFile(File file, JFileChooser chooser)
  7. setFileChooserFilters(JFileChooser fileDlg, String filters, int selectIndex)
  8. setSelectedFile(JFileChooser chooser, File file)
  9. SHOW_JFILECHOOSER(String title, String approvetext, int fileselectionmode, boolean multiselection)