Here you can find the source of setFile(File file, JFileChooser chooser)
Parameter | Description |
---|---|
file | a parameter |
chooser | a parameter |
public static void setFile(File file, JFileChooser chooser)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com) * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt ******************************************************************************/ import java.io.File; import javax.swing.JFileChooser; public class Main { /**//w w w . j a va 2s. c o m * Set JFileChooser so it will always make the best of going * to the location of the input file (whether its a file or directory) * @param file * @param chooser */ public static void setFile(File file, JFileChooser chooser) { if (file == null) { return; } // try turning into a directory if its a file that doesn't exist if (file.exists() == false && file.isFile()) { file = file.getParentFile(); } if (file.exists()) { if (file.isFile()) { chooser.setSelectedFile(file); } else if (file.isDirectory()) { chooser.setCurrentDirectory(file); } } } }