如何在所需目录中打开Filedialog

时间:2011-01-20 07:44:58

标签: java swing filedialog

我有两个按钮都打开了filedialog我想要的两个按钮应该总是在他们按下时在filedialog中打开他们的相关目录。在我的情况下,filedialog保留最后一个我不想要的打开目录。

1 个答案:

答案 0 :(得分:5)

你没有命名使用过的框架,但假设是Swing,JFileChooser有一些允许设置初始路径的构造函数:

JFileChooser(File currentDirectory)
      Constructs a JFileChooser using the given File as the path.

对于AWT框架中的FileDialog,使用setter在显示对话框之前设置目录

setDirectory(String dir)
      Sets the directory of this file dialog window to be the specified directory.