Here you can find the source of selectDirectory(Component component, String name, File pathToUse)
public static String selectDirectory(Component component, String name, File pathToUse)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.io.*; import javax.swing.JFileChooser; public class Main { private static File lastChooserPath; private static File lastIndicatedPath; public static String selectDirectory(Component component, String name, File pathToUse) { JFileChooser chooser = new JFileChooser(); boolean useIndicated = pathToUse != null; if (useIndicated && lastIndicatedPath == null) { lastIndicatedPath = pathToUse; }/*from www .j a v a 2s. c om*/ chooser.setCurrentDirectory(useIndicated ? lastIndicatedPath : lastChooserPath); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = chooser.showDialog(component, name); if (result == JFileChooser.APPROVE_OPTION) { try { if (useIndicated) { lastIndicatedPath = chooser.getCurrentDirectory(); } else { lastChooserPath = chooser.getCurrentDirectory(); } return chooser.getSelectedFile().getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); } } return null; } }