Here you can find the source of getOpenFile(String title)
public static File getOpenFile(String title)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.io.File; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JOptionPane; public class Main { public static File getOpenFile(String title) { JFileChooser chooser = getChooser(title); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); System.out.println("User chose file " + file.getAbsolutePath()); if (!file.exists()) { showMessage("File " + file.getName() + " doesn't exist, aborting"); return null; }//from ww w . j a v a 2 s .c o m return file; } else { showMessage("You must choose a file to load from"); return null; } } public static JFileChooser getChooser(String title) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(title); chooser.setPreferredSize(new Dimension(800, 600)); chooser.getActionMap().get("viewTypeDetails").actionPerformed(null); return chooser; } public static void showMessage(Object message) { JOptionPane pane = new JOptionPane(message, JOptionPane.WARNING_MESSAGE); JDialog dialog2 = pane.createDialog(null, "Message"); dialog2.setAlwaysOnTop(true); dialog2.setVisible(true); } }