package com.test;

import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * 选择文件的弹出窗口  使用JFileChooser
 * @author Administrator
 *
 */
public class JFileChooserTest {
		public static void main(String[] args) throws ClassNotFoundException,
				InstantiationException, IllegalAccessException,
				UnsupportedLookAndFeelException {
			String path = null;
			//设置界面风格
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			JFileChooser jdir = new JFileChooser();
			//设置选择路径模式
			jdir.setFileSelectionMode(JFileChooser.FILES_ONLY);
			//过滤文件类型
			FileNameExtensionFilter filter = new FileNameExtensionFilter(  
                     "Excel文件(*.xls;*.xlsx;)","xls","xlsx"); 
			jdir.setFileFilter(filter);
			//设置对话框标题
			jdir.setDialogTitle("请选择文件路径");
			if (JFileChooser.APPROVE_OPTION == jdir.showOpenDialog(null)) {//用户点击了确定
				path = jdir.getSelectedFile().getAbsolutePath();//取得路径选择
			}
			System.out.println(path);
		}
	}