Set source directory to SWT FileDialog

I am working on an RCP Eclipse project and should allow the user to select a file. For convenience, on the basis of certain conditions, before opening it, the source directory of the file selection dialog should be installed.

As I am attached to Eclipse RCP / SWT, I work with org.eclipse.swt.widgets.FileDialog .
The documentation of this FileDialog points to the use of the setFilterPath(String string) method, which should do exactly what I need (see the documentation ).

  FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterExtensions(new String [] {"*.html"}); dialog.setFilterPath("c:\\temp"); String result = dialog.open(); 

Unfortunately, it does not work, at least not “every time”.

I have no installation for verification, but I am sure that this function will work fully on a computer with Windows 200 / XP / Vista. I work with a Windows 7 machine and I think that I am suffering from the behavior described here for lpstrInitialDir .

At least, this is exactly the behavior I encountered. The path is good the first time you open a dialog, but the second time, the path is first set to the last path selected. In most cases, this seems convenient, but it's not mine.

Can this be right? If so, do I have a chance to change my behavior according to my needs?

Thanks for any answer!

+7
java swt rcp filedialog
source share
1 answer

Do you use the same FileDialog object when you reopen it?

I did some quick tests and found that if you reinstall filterPath again, the dialog will open in the right place.

If I open the same object again, it will start at a previously selected location.

0
source share

All Articles