5

I want to open a FileDialog window into the user home folder (i.e. /home/user or /Users/unsername)

I read the user home folder, using System.getProperty:

  String homefolder = System.getProperty(user.home);

And the variable containts the correct home folder. But when i set the filterpath in FileDialog, it opens (in linux) only the /home level not entering into the user home dir.

This is the source code:

  FileDialog dialog = new FileDialog(shell); 
  dialog.setText("Choose a certificate");
  String platform = SWT.getPlatform();
  String homefolder = System.getProperty("user.home");
  dialog.setFilterPath(homefolder);

Any idea? Here a screenshot: Swt FileDialog Problem

Charles
  • 50,943
  • 13
  • 104
  • 142
Ivan
  • 4,186
  • 5
  • 39
  • 72
  • Your code does open the home folder on my system. Did you verify that `homefolder` is the correct path? – Baz Dec 02 '12 at 10:06
  • yeah. The homfolder content is correct. But when i open the FileDialog it is on /home with the user folder selected. – Ivan Dec 02 '12 at 10:08
  • Which window manager are you using? – Baz Dec 02 '12 at 10:09
  • I use Kde as window manager. But the libraries used by swt doesn't seem to use any kde component. – Ivan Dec 02 '12 at 10:16
  • There is a bug report [here](https://bugs.eclipse.org/bugs/show_bug.cgi?id=287149), which states "fixed". Which version of SWT are you using? – Baz Dec 02 '12 at 10:19
  • 3.3.0-v3346 – Ivan Dec 02 '12 at 10:32
  • Well, there is your problem. It was fixed in 3.4. So, go ahead and just use a newer version. If this worked for you, I will create an answer that you can accept. – Baz Dec 02 '12 at 10:44
  • Yeah it worked :) (the problem was that i was using maven, and the official repository support only versions 3.2 and 3.3, i added another repository http://stackoverflow.com/questions/5096299/maven-project-swt-3-5-dependency-any-official-public-repo if you want you can add that in your answer). Thank you! – Ivan Dec 02 '12 at 10:57

1 Answers1

5

Your code works perfectly with SWT 3.6.1. There is a bug report here stating that this was a problem in SWT versions <= 3.3 and was fixed in 3.4.

So, the solution would be to install a never version (ideally the current version).

Since you mentioned that you use a Maven repository, there is one for SWT 3.8 here:

maven project: SWT 3.5 dependency: any official public repo?

Community
  • 1
  • 1
Baz
  • 36,440
  • 11
  • 68
  • 94