A BFileChooser is a Widget that allows the user to select files or directories from the
file system. It has modes for loading files, saving files, and choosing directories. It
supports both single and multiple selection modes, and you can optionally restrict the list of
files shown in the dialog by setting a FileFilter.
BFileChooser can be used in two different ways. First, it can be added to a container like
any other Widget. This is useful when you want it to appear inside of a window along with
other Widgets.
Most often, however, BFileChooser is used in a modal dialog as a self contained user interface
element. To use it this way, you simply instantiate a BFileChooser, set any properties, and then
call
showDialog()
to display it.
showDialog()
will
automatically create a dialog, add the BFileChooser, display it, and block until the user
dismisses the dialog. You can reuse a single BFileChooser by repeatedly calling
showDialog()
.
In addition to the event types generated by all Widgets, BFileChoosers generate the following event types:
getDirectory
public File getDirectory()
Get the directory displayed in this file chooser.
getFileFilter
public FileFilter getFileFilter()
Get the FileFilter which restricts the list of files shown in the dialog.
getMode
public BFileChooser.SelectionMode getMode()
Get the select mode for this file chooser (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER).
getSelectedFile
public File getSelectedFile()
Get the file selected in the file chooser. If multiple files are selected, no guarantees
are made about which one will be returned, so you should use
getSelectedFiles()
instead of this method whenever multiple selection is enabled.
If no file is selected, this returns null.
getSelectedFiles
public File[] getSelectedFiles()
Get the list of selected files. This should be used instead of getSelectedFile()
when multiple selection is enabled.
getTitle
public String getTitle()
Get the title displayed on the dialog.
isMultipleSelectionEnabled
public boolean isMultipleSelectionEnabled()
Get whether the user is allowed to select multiple files.
setDirectory
public void setDirectory(File directory)
Set the directory displayed in this file chooser.
setFileFilter
public void setFileFilter(FileFilter filter)
Set the FileFilter which restricts the list of files shown in the dialog.
setMode
public void setMode(BFileChooser.SelectionMode mode)
Set the select mode for this file chooser (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER).
setMultipleSelectionEnabled
public void setMultipleSelectionEnabled(boolean multiple)
Set whether the user is allowed to select multiple files.
setSelectedFile
public void setSelectedFile(File file)
Set the file selected in the file chooser.
setSelectedFiles
public void setSelectedFiles(files[] )
throws IllegalArgumentException
Set the list of selected files.
setTitle
public void setTitle(String title)
Set the title displayed on the dialog.
showDialog
public boolean showDialog(Widget parent)
Show a dialog containing this BFileChooser and block until the user closes it. After this method
returns, you can call getSelectedFile()
or getSelectedFiles()
to
determine which file or files were selected.
parent
- the dialog's parent Widget (usually a WindowWidget). This may be null.
- true if the user clicked the accept button (usually labelled "Open" or "Save"),
false if they clicked the cancel button