import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File; import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel; @SuppressWarnings("serial")
public class Filechooser extends JFrame implements ActionListener{ JButton open=null;
public static void main (String[] args){
new Filechooser();//构造一个指向用户的默认目录Filechooser
}
public Filechooser(){
open=new JButton("打开");
this.add(open);
this.setBounds(100,100,100,100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
open.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
JFileChooser j=new JFileChooser();
j.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);//设置Filechooser
j.showDialog(new JLabel(),"选择");// 弹出具有自己定义 approve button的自己定义文件选择器对话框
File file=j.getSelectedFile();
if(file.isDirectory()){
System.out.println("目录 "+file.getAbsolutePath()); }else if(file.isFile()){
System.out.println("目录 "+file.getAbsolutePath());
}
System.out.println(j.getSelectedFile().getName()); }
}
<img src="http://img.blog.csdn.net/20150703133924135?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXlha2FrYXpl/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

最新文章

  1. F#之旅3 - F# PK C#:简单的求和
  2. linuxmint 17没有vim
  3. 一些sql二
  4. 从数学角度看最大期望(EM)算法 II
  5. CoreAnimation-07-CAAnimationGroup
  6. 由IP和掩码计算广播地址
  7. Linux下SSH各配置项解释
  8. posix thread概述
  9. 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程01: 资源导入》
  10. golang_protobuf环境搭建
  11. Python 中的类的相关操作
  12. http response
  13. viewpager处理(一):让viewpager不能滑动
  14. 详细的css命名规则,专业点吧
  15. Spring3.0官网文档学习笔记(二)
  16. 洛谷 [P2774] 方格取数问题
  17. Redis数据结构简介
  18. phpstorm 代码注释后,撤销某段代码的注释的,快捷键是什么?
  19. Redis持久化存储(AOF与RDB两种模式)
  20. MVC+Nhibernate+spring.net(一)

热门文章

  1. checkbox、radio设置自定义样式
  2. 如何生成WebAssembly文件?
  3. vue注册和简单使用
  4. 01背包-dp
  5. SFTPUtils工具类及使用
  6. Kotlin基础(一)Kotlin快速入门
  7. GPIOLED配置、key、中断NVIC配置
  8. HTML(三)
  9. python系统编程(十一)
  10. 3ds max学习笔记(二)--查看视点