JFileChooser更改Windows中的默认目录 [英] JFileChooser change default directory in Windows

查看:95
本文介绍了JFileChooser更改Windows中的默认目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows上将我的JFileChooser的默认目录更改为我的音乐。
这个目录是 C:\ Users \Fre\Music 在我的帐户上,因为我的用户名是 Fre

I want to change the default directory of my JFileChooser to "My Music" on Windows. This directory is C:\Users\Fre\Music on my account because my username is Fre

默认设置在 C:\ Users \Fre \Documents (取决于操作系统)我认为)。
我该如何更改?

The default is set on C:\Users\Fre\Documents (depends on OS i think). How can I change this?

推荐答案

您可以使用API​​方法 setCurrentDirectory

You can use the API method setCurrentDirectory when initializing your JFileChooser objects:

public void setCurrentDirectory(File dir)

示例用法可能如下:

yourFileChooser.setCurrentDirectory(new File  
(System.getProperty("user.home") + System.getProperty("file.separator")+ "Music"));

这篇关于JFileChooser更改Windows中的默认目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆