JFileChooser的使用
来源:互联网 发布:wamp apache无法启动 编辑:程序博客网 时间:2024/06/06 00:29
package com.cumt;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; public class FileChooser extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L;JButton open=null; public static void main(String[] args) { new FileChooser(); } /** * 无参构造器 JFileChooser()-->构造一个指向用户默认目录的 JFileChooser * 带参数的构造器JFileChooser(File currentDirectory)-->使用给定的 File 作为路径来构造一个 JFileChooser */ public FileChooser(){ open=new JButton("open"); this.add(open); this.setBounds(400, 200, 100, 100); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); open.addActionListener(this); } @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc=new JFileChooser(); //设置文件选择模式是文件和目录都可见 jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES ); //弹出选择文件或路径对话框 jfc.showDialog(new JLabel(), "选择"); //得到选择的文件或文件夹的file File file=jfc.getSelectedFile(); if(file.isDirectory()){ System.out.println("文件夹:"+file.getAbsolutePath()); }else if(file.isFile()){ System.out.println("文件:"+file.getAbsolutePath()); } System.out.println(jfc.getSelectedFile().getName()); } }
1 0
- JFileChooser的使用
- JFileChooser的使用
- jfilechooser 的使用 监听
- JFileChooser的使用
- JFileChooser的简单使用
- JFileChooser的使用
- JFileChooser的简单使用
- JFileChooser的简单使用
- JFileChooser和FileFilter的使用
- java Swing JFileChooser 的使用
- JFileChooser和FileFilter的使用
- JFileChooser(文件选择器)的使用
- 文件选择框JFileChooser的使用
- 使用JFileChooser打开文件
- 使用JFileChooser保存文件
- JAVASE中JFileChooser的使用小结 打开文件并显示
- Java Swing 使用JFileChooser保存带自定义后缀名的文件
- JFileChooser &FileDialog 的异同
- LeetCode OJ 之 Ugly Number (丑数)
- 前端JavaScript规范 非常详细
- iOS 截取图片,并且保持图片原有比例,同时填充imageView
- 第六章指针和基于指针的字符串
- Java 内存区域和GC机制
- JFileChooser的使用
- 九度OJ 题目1061:成绩排序
- 黑马程序员———C语言———【数据结构:单链表】
- make的时候能够检查头文件是否有更新过
- Ibatis知道(一)
- Oracle-----Update语句优化之merge into
- 7 款开源 Java 反编译工具
- LeetCode OJ 之 Ugly Number II (丑数-二)
- 5-2 派生类的构造函数