有没有办法让java文件选择对话框记住最后一个目录? [英] Is there any way to make java file selection dialogs remember the last directory?

查看:153
本文介绍了有没有办法让java文件选择对话框记住最后一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用java应用程序时,每次打开对话框时,起始目录始终是我的主目录。有没有办法让它记住上次使用的目录?或者,是否有改进的java文件选择对话框,允许进行类型到搜索或大多数其他应用程序文件选择对话框中标准的任何功能?

When using java applications, every time I open a dialog box, the starting directory is always my home directory. Is there any way to make it remember the last used directory? Alternately, are there 'improved' java file selection dialogs that allow type-to-search or any of the features that are standard in most other application file selection dialogs?

编辑:我认为发布的答案解决了编写 java应用程序的问题,但不适用于用户。也许用户不可能更改文件浏览器界面,但我想知道这一点。如果它很重要,我会考虑一些具体的例子(亚马逊AWS上传器),但我观察到大多数使用文件浏览器的java应用程序中的行为。

I think the answers posted address the question for writing java applications, but not for a user. Perhaps it's not possible for the user to change the file browser interface, but I'd like to know that. In case it matters, I have a few specific examples in mind (Amazon AWS uploader) but I have observed that behavior in most java applications that use a file browser.

推荐答案

将文件选择器存储为类属性。重新打开时,将保留以下内容。

Store the file chooser as a class attribute. When it is re-opened, the following will be preserved.


  1. 目录。

  2. 放置在用户滚动目录的目录中。

  3. 选定的文件过滤器。

  4. 大小。

  5. 屏幕上的位置。

  6. PLAF。

  7. ..

  1. The directory.
  2. The place in the directory to where the user had scrolled.
  3. The selected file filter.
  4. The size.
  5. The location on screen.
  6. The PLAF.
  7. ..








有没有办法让它记住上次使用的目录?

Is there any way to make it remember the last used directory?

当然,如果你的意思是在运行之间保持状态有许多其他形式的存储细节,以及存储它们的地方/方式。
请参阅这回答有关使用属性文件存储 JFrame 的边界的示例。

Of course, if you mean persist the state between runs, there are a number of alternative forms of storing the details, and places/ways to store them. See this answer for an example of storing the bounds of a JFrame using a Properties file.


也许用户无法更改文件浏览器界面,..

Perhaps it's not possible for the user to change the file browser interface, ..

'用户'是什么?您是指在应用程序中使用一个的开发人员吗?

What 'user'? Do you mean the developer who uses one in an app.?

您可能需要的是实现自己的文件选择器。如果是这种情况,您可以从 FileBro 代码开始。

Maybe what you need is to implement your own file chooser. If that is the case, you might start with the FileBro code.

这篇关于有没有办法让java文件选择对话框记住最后一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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