SWT FileDialog and Windows Hide Extensions For Known File Types

This morning we encountered a strange difference while running the following code on two Windows workstations and directly clicking the OK button of the dialog.

 FileDialog dialog = new FileDialog(window.getShell(), SWT.SAVE);
 dialog.setText("Save as...");
 dialog.setFilterExtensions(new String[]{"*.sav"});
 String path = dialog.open();

The first workstation printed C:\Test\toSave.test while the second one printed C:\Test\toSave.test.sav

Of course the wanted behaviour is the second one !!!

After investigations we identified the difference on the workstations causing this “SWT” difference: the first workstation HAS the windows folder option called Hide Extensions For Known File Types checked while the second one HASN’T !!!

To fix the issue we had to modify the setFileName method call as following:


Conclusion: Looking back to the initial code, it seems logic to have to set a file name matching the specified filter extensions.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s