tags:

views:

60

answers:

1

In our installation program I want to enable users to use install directory which, obviously, does not exist yet. I want that when the Browse button is pressed, a JFileChooser dialog will be opened, and will be initialized with the currently selected directory. However, setCurrentDirectory only works with existing directories, and setSelectedFile only seems to work when not working with DIRECTORIES_ONLY like I do.

Is there any way around this?

Thanks,

splintor

+1  A: 

This is the (partial) solution I found. It is good enough for me:

JFileChooser fc = new JFileChooser(initialExistingDirectory);
FileChooserUI fileChooserUI = fc.getUI();
if (fileChooserUI instanceof BasicFileChooserUI)
{
    BasicFileChooserUI basicFileChooserUI = (BasicFileChooserUI) fileChooserUI;
    basicFileChooserUI.setFileName(initialNonExistingDirectory);
}
splintor