0

To date I only used Swing to build graphical user interfaces but now I also want to make myself familiar with the Standard Widget Toolkit. I already read the documentation and built a simple app. My problem is now to use the FileDialog component.

I did the following code:

FileDialog openFileDialog = new FileDialog(shell, SWT.OPEN);
openFileDialog.setFilterExtensions(new String[] { "*.txt" });
openFileDialog.setFilterNames(new String[] { "Text files (*.txt)" });
openFileDialog.setText("Open file");
openFileDialog.open();

But I found no methods to set flags like "PathMustExists" or "FileMustExists". Is this not possible with FileDialog? Do I have to extend the class to implement that functionality? If so, how I have to proceed? Or this there a better OpenFileDialog component (maybe in JFace) from which I don't know?

altralaser
  • 2,035
  • 5
  • 36
  • 55

1 Answers1

2

There are no options for this.

Since you are specifying SWT.OPEN you will get a file dialog specialized for opening existing files. Depending on which platform you are running on this dialog may not allow non-existent files to be selected at all (certainly true on Mac OS X). Still you should check the file after the dialog returns.

RĂ¼diger Herrmann
  • 20,512
  • 11
  • 62
  • 79
greg-449
  • 109,219
  • 232
  • 102
  • 145