Here you can find the source of newFileChooser(String dialogTitle, int fileSelectionMode, JTextField textField, String globalLocation)
public static JFileChooser newFileChooser(String dialogTitle, int fileSelectionMode, JTextField textField, String globalLocation)
//package com.java2s; //License from project: Apache License import java.io.File; import javax.swing.JFileChooser; import javax.swing.JTextField; public class Main { public static JFileChooser newFileChooser(String dialogTitle, int fileSelectionMode, JTextField textField, String globalLocation) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(dialogTitle); fileChooser.setFileSelectionMode(fileSelectionMode); if (!textField.getText().trim().isEmpty()) setCurrentDirectory(fileChooser, textField.getText().trim()); else if (null != globalLocation && !globalLocation.isEmpty()) setCurrentDirectory(fileChooser, globalLocation); return fileChooser; }/*from w ww .j a v a 2 s . c om*/ 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); } private static boolean pointsToFile(String location) { if (location.lastIndexOf("\\") < location.lastIndexOf(".")) return true; return false; } }