Here you can find the source of loadFile(Component parent, String title)
Parameter | Description |
---|---|
parent | If you want to attach it to the opener window. May be null. |
title | For the dialog window. |
public static java.io.File loadFile(Component parent, String title)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import javax.swing.JFileChooser; public class Main { /**//from w w w. j a v a2 s . c om * This method is used to choose a file path. * @param parent If you want to attach it to the opener window. May be null. * @param title For the dialog window. * @return */ public static java.io.File loadFile(Component parent, String title) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File("./")); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setVisible(true); if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } return null; } }