Here you can find the source of getLoadFilename(Component parent)
Parameter | Description |
---|---|
parent | a parameter |
public static File getLoadFilename(Component parent)
//package com.java2s; // Released under Open Works License, http://owl.apotheon.org/ import java.awt.Component; import java.io.*; import javax.swing.*; public class Main { private final static JFileChooser _fileChooser = new JFileChooser(System.getProperty("user.dir")); /**/* w w w . j ava 2s. c o m*/ * Get a filename to load from. * * @param parent * @return */ public static File getLoadFilename(Component parent) { _fileChooser.setMultiSelectionEnabled(false); _fileChooser.setSelectedFile(new File("x")); // clear the previous selection _fileChooser.setSelectedFile(new File("")); int option = _fileChooser.showOpenDialog(parent); if (option == JFileChooser.APPROVE_OPTION) { File filename = _fileChooser.getSelectedFile(); if (filename.exists()) { return filename; } else { JOptionPane.showMessageDialog(parent, "File " + filename.getName() + " does not exist. You need to select an existing file.", "Error: No file exists", JOptionPane.ERROR_MESSAGE); return getLoadFilename(parent); } } return null; } }