Package org.eclipse.swt.widgets

## Class FileDialog

- java.lang.Object
- - org.eclipse.swt.widgets.Dialog
  - - org.eclipse.swt.widgets.FileDialog

    public class FileDialog
    extends Dialog

Instances of this class allow the user to navigate the file system and select or enter a file name.

Styles:
  SAVE, OPEN, MULTI
Events:
  (none)

Note: Only one of the styles SAVE and OPEN may be specified.

IMPORTANT: This class is not intended to be subclassed.

See Also:
  FileDialog snippets, SWT Example: ControlExample, Dialog tab, Sample code and further information
Restriction:
  This class is not intended to be subclassed by clients.

### Constructor Summary

Constructors
`FileDialog​(Shell parent)` Constructs a new instance of this class given only its parent.
`FileDialog​(Shell parent, int style)` Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

### Method Summary

All Methods Instance Methods Concrete Methods
`String` `getFileName()` Returns the path of the first file that was selected in the dialog relative to the filter path, or an empty string if no such file has been selected.
`String[]` `getFileNames()` Returns a (possibly empty) array with the paths of all files that were selected in the dialog relative to the filter path.
`String[]` `getFilterExtensions()` Returns the file extensions which the dialog will use to filter the files it shows.
`int` `getFilterIndex()` Get the 0-based index of the file extension filter which was selected by the user, or -1 if no filter was selected.
`String[]` `getFilterNames()` Returns the names that describe the filter extensions which the dialog will use to filter the files it shows.
`String` `getFilterPath()` Returns the directory path that the dialog will use, or an empty string if this is not set.
`boolean` `getOverwrite()` Returns the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.
`String` `open()` Makes the dialog visible and brings it to the front of the display.
`void` `setFileName​(String string)` Set the initial filename which the dialog will select by default when opened to the argument, which may be null.
`void` `setFilterExtensions​(String[] extensions)` Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.
`void` `setFilterIndex​(int index)` Set the 0-based index of the file extension filter which the dialog will use initially to filter the files it shows to the argument.
`void` `setFilterNames​(String[] names)` Sets the names that describe the filter extensions which the dialog will use to filter the files it shows to the argument, which may be null.
`void` `setFilterPath​(String string)` Sets the directory path that the dialog will use to the argument, which may be null.
`void` `setOverwrite​(boolean overwrite)` Sets the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.

### Methods inherited from class org.eclipse.swt.widgets.Dialog

`checkSubclass, getParent, getStyle, getText, setText`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FileDialog

    public FileDialog​(Shell parent)

Constructs a new instance of this class given only its parent.

Parameters:
  `parent` - a shell which will be the parent of the new instance
Throws:
  `IllegalArgumentException` -
  - ERROR_NULL_ARGUMENT - if the parent is null
  `SWTException` -
  - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  - ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass

#### FileDialog

    public FileDialog​(Shell parent,
                      int style)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class `SWT` which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the `int` "|" operator) two or more of those `SWT` style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters:
  `parent` - a shell which will be the parent of the new instance
  `style` - the style of dialog to construct
Throws:
  `IllegalArgumentException` -
  - ERROR_NULL_ARGUMENT - if the parent is null
  `SWTException` -
  - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  - ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
See Also:
  `SWT.SAVE`, `SWT.OPEN`, `SWT.MULTI`

### Method Detail

#### getFileName

    public String getFileName()

Returns the path of the first file that was selected in the dialog relative to the filter path, or an empty string if no such file has been selected.

Returns:
  the relative path of the file

#### getFileNames

    public String[] getFileNames()

Returns a (possibly empty) array with the paths of all files that were selected in the dialog relative to the filter path.

Returns:
  the relative paths of the files

#### getFilterExtensions

    public String[] getFilterExtensions()

Returns the file extensions which the dialog will use to filter the files it shows.

Returns:
  the file extensions filter

#### getFilterIndex

    public int getFilterIndex()

Get the 0-based index of the file extension filter which was selected by the user, or -1 if no filter was selected.

This is an index into the FilterExtensions array and the FilterNames array.

Returns:
  index the file extension filter index
Since:
  3.4
See Also:
  `getFilterExtensions()`, `getFilterNames()`

#### getFilterNames

    public String[] getFilterNames()

Returns the names that describe the filter extensions which the dialog will use to filter the files it shows.

Returns:
  the list of filter names

#### getFilterPath

    public String getFilterPath()

Returns the directory path that the dialog will use, or an empty string if this is not set. File names in this path will appear in the dialog, filtered according to the filter extensions.

Returns:
  the directory path string
See Also:
  `setFilterExtensions(java.lang.String[])`

#### getOverwrite

    public boolean getOverwrite()

Returns the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.

Returns:
  true if the dialog will prompt for file overwrite, false otherwise
Since:
  3.4

#### open

    public String open()

Makes the dialog visible and brings it to the front of the display.

Returns:
  a string describing the absolute path of the first selected file, or null if the dialog was cancelled or an error occurred
Throws:
  `SWTException` -
  - ERROR_WIDGET_DISPOSED - if the dialog has been disposed
  - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog

#### setFileName

    public void setFileName​(String string)

Set the initial filename which the dialog will select by default when opened to the argument, which may be null. The name will be prefixed with the filter path when one is supplied.

Parameters:
  `string` - the file name

#### setFilterExtensions

    public void setFilterExtensions​(String[] extensions)

Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.

The strings are platform specific. For example, on some platforms, an extension filter string is typically of the form "*.extension", where "*.*" matches all files. For filters with multiple extensions, use semicolon as a separator, e.g. "*.jpg;*.png".

Note: On Mac, setting the file extension filter affects how app bundles are treated by the dialog. When a filter extension having the app extension (.app) is selected, bundles are treated as files. For all other extension filters, bundles are treated as directories. When no filter extension is set, bundles are treated as files.

Parameters:
  `extensions` - the file extension filter
See Also:
  `to specify the user-friendly names corresponding to the extensions`

#### setFilterIndex

    public void setFilterIndex​(int index)

Set the 0-based index of the file extension filter which the dialog will use initially to filter the files it shows to the argument.

This is an index into the FilterExtensions array and the FilterNames array.

Parameters:
  `index` - the file extension filter index
Since:
  3.4
See Also:
  `setFilterExtensions(java.lang.String[])`, `setFilterNames(java.lang.String[])`

#### setFilterNames

    public void setFilterNames​(String[] names)

Sets the names that describe the filter extensions which the dialog will use to filter the files it shows to the argument, which may be null.

Each name is a user-friendly short description shown for its corresponding filter. The `names` array must be the same length as the `extensions` array.

Parameters:
  `names` - the list of filter names, or null for no filter names
See Also:
  `setFilterExtensions(java.lang.String[])`

#### setFilterPath

    public void setFilterPath​(String string)

Sets the directory path that the dialog will use to the argument, which may be null. File names in this path will appear in the dialog, filtered according to the filter extensions. If the string is null, then the operating system's default filter path will be used.

Note that the path string is platform dependent. For convenience, either '/' or '\' can be used as a path separator.

Parameters:
  `string` - the directory path
See Also:
  `setFilterExtensions(java.lang.String[])`

#### setOverwrite

    public void setOverwrite​(boolean overwrite)

Sets the flag that the dialog will use to determine whether to prompt the user for file overwrite if the selected file already exists.

Parameters:
  `overwrite` - true if the dialog will prompt for file overwrite, false otherwise
Since:
  3.4