如何设置jfilechooser的打开路径
展开全部
如何设置jfilechooser的打开路径
量身打造 请测试...import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.Properties;public class FileChooser extends JFrame implements ActionListener{
private JButton open;
private JFileChooser chooser;
private String latestPath ;
private Profile profile;
public FileChooser() {
profile = new Profile();//每次运行程序时创建配置文件Profile对象
latestPath = (profile.read()?profile.latestPath:"C:/");//读取配置文件里的参数Profile并赋值给latestPath
open = new JButton("open");
this.add(open);
this.setSize(200,150);
this.setLocationRelativeTo(null);//窗口居中
this.setVisible(true);
open.addActionListener(this);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
profile.write(latestPath);//每次退出程序时把最后一次打开的目录写入到配置文件
}
});
量身打造 请测试...import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.Properties;public class FileChooser extends JFrame implements ActionListener{
private JButton open;
private JFileChooser chooser;
private String latestPath ;
private Profile profile;
public FileChooser() {
profile = new Profile();//每次运行程序时创建配置文件Profile对象
latestPath = (profile.read()?profile.latestPath:"C:/");//读取配置文件里的参数Profile并赋值给latestPath
open = new JButton("open");
this.add(open);
this.setSize(200,150);
this.setLocationRelativeTo(null);//窗口居中
this.setVisible(true);
open.addActionListener(this);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
profile.write(latestPath);//每次退出程序时把最后一次打开的目录写入到配置文件
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询