Java tutorial
//package com.java2s; import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; public class Main { static File lastDirectory; public static JFileChooser createFileChooser(String title, FileFilter filter, int mode, boolean multiSelectionEnabled, int dialogType) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(title); fileChooser.setFileFilter(filter); fileChooser.setFileSelectionMode(mode); fileChooser.setDialogType(dialogType); fileChooser.setMultiSelectionEnabled(multiSelectionEnabled); fileChooser.setCurrentDirectory(getLastDirectory()); return fileChooser; } public static File getLastDirectory() { if (lastDirectory == null) { String home = System.getProperty("user.home"); lastDirectory = home != null && !home.isEmpty() ? new File(home) : File.listRoots()[0]; } return lastDirectory; } }