Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public Class FileDialog

extends Dialog
Class Inheritance
Imports
java.io.*, org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

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 Note

This class is not intended to be subclassed.

See Also
FileDialog snippets, SWT Example: ControlExample, Dialog tab, Sample code and further information

Field Summary

Modifier and TypeField and Description
pack-priv static final char
pack-priv static final char
pack-priv String
pack-priv String[]
pack-priv String[]
pack-priv int
pack-priv String[]
pack-priv String
pack-priv String
pack-priv long
pack-priv boolean
pack-priv static final char
pack-priv boolean
Inherited from org.eclipse.swt.widgets.Dialog:
parentstyletitle

Constructor Summary

AccessConstructor and Description
public
FileDialog(Shell
a shell which will be the parent of the new instance
parent
)

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

public
FileDialog(Shell
a shell which will be the parent of the new instance
parent
,
int
the style of dialog to construct
style
)

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

Method Summary

Modifier and TypeMethod and Description
pack-priv String
public String

Returns:

the relative path of the file
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.

public String[]

Returns:

the relative paths of the files
getFileNames
()

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

public String[]

Returns:

the file extensions filter
getFilterExtensions
()

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

public int

Returns:

index the file extension filter index
getFilterIndex
()

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

public String[]

Returns:

the list of filter names
getFilterNames
()

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

public String

Returns:

the directory path string
getFilterPath
()

Returns the directory path that the dialog will use, or an empty string if this is not set.

public boolean

Returns:

true if the dialog will prompt for file overwrite, false otherwise
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.

private boolean

Returns:

true if the extension contains any of the glob pattern wildcards
isGlobPattern
(String
file extension as a string
extension
)

Check whether the file extension is a glob pattern.

public String

Returns:

a string describing the absolute path of the first selected file, or null if the dialog was cancelled or an error occurred
open
()

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

pack-priv String

Returns:

a string describing the absolute path of the first selected file, or null
openNativeChooserDialog
()

Open the file chooser dialog using the GtkFileChooserNative API (GTK3.20+) for running applications without direct filesystem access (such as Flatpak).

pack-priv void
public void
setFileName(String
the file name
string
)

Set the initial filename which the dialog will select by default when opened to the argument, which may be null.

public void
setFilterExtensions(String[]
the file extension filter
extensions
)

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

public void
setFilterIndex(int
the file extension filter index
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.

public void
setFilterNames(String[]
the list of filter names, or null for no filter names
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.

public void
setFilterPath(String
the directory path
string
)

Sets the directory path that the dialog will use to the argument, which may be null.

public void
setOverwrite(boolean
true if the dialog will prompt for file overwrite, false otherwise
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.

pack-priv void
setURIMode(boolean uriMode)

Inherited from org.eclipse.swt.widgets.Dialog:
checkParentcheckStylecheckSubclasserrorgetParentgetStylegetTextsetText

Field Detail

EXTENSION_SEPARATORback to summary
pack-priv static final char EXTENSION_SEPARATOR
FILE_EXTENSION_SEPARATORback to summary
pack-priv static final char FILE_EXTENSION_SEPARATOR
fileNameback to summary
pack-priv String fileName
fileNamesback to summary
pack-priv String[] fileNames
filterExtensionsback to summary
pack-priv String[] filterExtensions
filterIndexback to summary
pack-priv int filterIndex
filterNamesback to summary
pack-priv String[] filterNames
filterPathback to summary
pack-priv String filterPath
fullPathback to summary
pack-priv String fullPath
handleback to summary
pack-priv long handle
overwriteback to summary
pack-priv boolean overwrite
SEPARATORback to summary
pack-priv static final char SEPARATOR
uriModeback to summary
pack-priv boolean uriMode

Constructor Detail

FileDialogback to summary
public FileDialog(Shell parent)

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

Parameters
parent:Shell

a shell which will be the parent of the new instance

Exceptions
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
FileDialogback to summary
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:Shell

a shell which will be the parent of the new instance

style:int

the style of dialog to construct

Exceptions
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

computeResultChooserDialogback to summary
pack-priv String computeResultChooserDialog()
getFileNameback to summary
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:String

the relative path of the file

getFileNamesback to summary
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:String[]

the relative paths of the files

getFilterExtensionsback to summary
public String[] getFilterExtensions()

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

Returns:String[]

the file extensions filter

getFilterIndexback to summary
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:int

index the file extension filter index

Since
3.4
See Also
getFilterExtensions, getFilterNames
getFilterNamesback to summary
public String[] getFilterNames()

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

Returns:String[]

the list of filter names

getFilterPathback to summary
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:String

the directory path string

See Also
setFilterExtensions
getOverwriteback to summary
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:boolean

true if the dialog will prompt for file overwrite, false otherwise

Since
3.4
isGlobPatternback to summary
private boolean isGlobPattern(String extension)

Check whether the file extension is a glob pattern. For example, *.* is a glob pattern which corresponds to all files *.jp* corresponds to all the files with extension starting with jp like jpg,jpeg etc *.jp? corresponds to 3 letter extension starting with jp with any 3rd letter *.[pq]ng this corresponds to *.png and *.qng

Parameters
extension:String

file extension as a string

Returns:boolean

true if the extension contains any of the glob pattern wildcards

openback to summary
public String open()

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

Returns:String

a string describing the absolute path of the first selected file, or null if the dialog was cancelled or an error occurred

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the dialog has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog
openNativeChooserDialogback to summary
pack-priv String openNativeChooserDialog()

Open the file chooser dialog using the GtkFileChooserNative API (GTK3.20+) for running applications without direct filesystem access (such as Flatpak). API for GtkFileChoosernative does not give access to any GtkWindow or GtkWidget for the dialog, thus this method omits calls that requires such access. These are be handled by the GtkNativeDialog API.

Returns:String

a string describing the absolute path of the first selected file, or null

presetChooserDialogback to summary
pack-priv void presetChooserDialog()
setFileNameback to summary
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:String

the file name

setFilterExtensionsback to summary
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:String[]

the file extension filter

See Also
to specify the user-friendly names corresponding to the extensions
setFilterIndexback to summary
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:int

the file extension filter index

Since
3.4
See Also
setFilterExtensions, setFilterNames
setFilterNamesback to summary
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:String[]

the list of filter names, or null for no filter names

See Also
setFilterExtensions
setFilterPathback to summary
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:String

the directory path

See Also
setFilterExtensions
setOverwriteback to summary
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.

Note

On some platforms where suppressing the overwrite prompt is not supported, the prompt is shown even when invoked with overwrite false.

Parameters
overwrite:boolean

true if the dialog will prompt for file overwrite, false otherwise

Since
3.4
setURIModeback to summary
pack-priv void setURIMode(boolean uriMode)