简体   繁体   English

是否可以在打开时将默认文件夹路径放入 showOpenDialog 文件名 TextArea 中?

[英]Is it posible to put default folder path into showOpenDialog File Name TextArea at openning?

When the ShowOpenDialog window is opened, the address of the default folder path address does not automatically appear in the file name text area.当 ShowOpenDialog 窗口打开时,默认文件夹路径地址的地址不会自动出现在文件名文本区域中。 The user has to choose a folder or file.用户必须选择一个文件夹或文件。 However, I want to put the address of the default folder in the file name text area at starting.但是,我想在开始时将默认文件夹的地址放在文件名文本区域中。 So the user enter image description here be able to select the default folder just by pressing the open button.所以用户在这里输入图像描述就可以通过按下打开按钮来选择默认文件夹。

Unfortunately, the setcurrentdirectory method only shows the files and folders under the relevant folder and the filename field is empty.不幸的是,setcurrentdirectory 方法只显示相关文件夹下的文件和文件夹,并且文件名字段为空。

The closest what I think is possible what you want is the following:我认为最接近您想要的是以下内容:

JFileChooser jFileChooser = new JFileChooser("C:\\Windows\\");
jFileChooser.setSelectedFile(new File("Downloaded Program Files"));
BasicFileChooserUI ui = (BasicFileChooserUI) jFileChooser.getUI();
ui.setFileName("C:\\Windows\\Downloaded Program Files");
jFileChooser.showOpenDialog(null);

Ie you would rather show the parent folder and then chose the folder you want to to be selected.即您宁愿显示父文件夹,然后选择要选择的文件夹。 This doesn't show you the whole path, but from the user point of view I think it's what you wanted.这并没有向您展示整个路径,但从用户的角度来看,我认为这就是您想要的。

Edit: I added some solution for your problem.编辑:我为您的问题添加了一些解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM