文件选择器JFileChooser
来源:互联网 发布:车辆维修记录软件 编辑:程序博客网 时间:2024/06/05 11:16
JFileChooser 的默认界面比较丑,一般的使用方法如下图所示
这里我要简略的介绍两种文件选择的窗口 1、JFileChooser 2、FileDialog
JFileChooser 的通常用法如下:
JFileChooser chooser=new JFileChooser();chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);//设置只能选择文件chooser.setMultiSelectionEnabled(false);//设置文件不可多选chooser.setFileFilter(new FileNameExtensionFilter("JPG文件", "jpg"));int result=chooser.showOpenDialog(SaveInMySql.this);if(result==JFileChooser.APPROVE_OPTION)//打开文件选择器{pf=new PictureFile();File f=chooser.getSelectedFile();String name=f.getName();textField.setText(name);pf.setPicture(f);pf.setFileName(name);}
效果如下图所示
如果想给其修饰一下,如下代码所示
JFileChooser chooser =new JFileChooser();String lookAndFeel = UIManager.getSystemLookAndFeelClassName();try {UIManager.setLookAndFeel(lookAndFeel);} catch (ClassNotFoundException | InstantiationException| IllegalAccessException | UnsupportedLookAndFeelException e) {// TODO Auto-generated catch blocke.printStackTrace();}SwingUtilities.updateComponentTreeUI(chooser);//使设置得界面风格生效chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//设置只显示目录chooser.showOpenDialog(frame);
FileDialog 的使用如下
FileDialog dialog=new FileDialog(this);dialog.setVisible(true);String path=dialog.getDirectory();File f=new File(path);File[] fs=f.listFiles(new java.io.FileFilter() {@Overridepublic boolean accept(File pathname) {// TODO Auto-generated method stubif(pathname.getName().endsWith("tem")){return true;}else{return false;}}});
比较简单就不添加注释了
阅读全文
0 0
- 文件选择器(JFileChooser)
- 文件选择器(JFileChooser)
- 文件选择器(JFileChooser)
- 文件选择器JFileChooser
- JFileChooser 文件选择器
- 文件选择器JFileChooser的创建
- JFileChooser文件保存位置选择器
- JFileChooser(文件选择器)的使用
- JavaSwing_4.3: JFileChooser(文件选择器)
- JAVA Swing图形化编程(一)文件选择器JFileChooser
- Java_简易记事本_文件选择器(JFileChooser)
- JAVA 文件对话框JFileChooser
- JFileChooser文件过滤
- jFileChooser showSaveDialog 保存文件
- jFileChooser showSaveDialog 保存文件
- java JFileChooser 文件过滤
- JFileChooser 文件类别 过滤
- jFileChooser showSaveDialog 保存文件
- 【Java学习笔记】26:打印流&数据流
- ViewPager加载不出View的解决方法
- Integer.parseInt("") Integer.valueOf("")和new Integer("")之间的区别
- 6 Major Differences between English and Chinese
- MathType和Office 2016兼容设置
- 文件选择器JFileChooser
- * 24种设计模式——桥梁模式
- 在centos中使用yum安装mongodb
- 简单商品管理
- 问题 X: 个位数统计
- Arduino 控制 DS1302 时钟芯片
- C++面向对象的三大特征——多态(静态多态)
- 浅谈分布式消息技术:Kafka
- HDU 4714 树的切割拼装成环