public class FileDialog extends Dialog
The FileDialog
class displays a dialog window from which the user can select a file.
Since it is a modal dialog, when the application calls its show
method to display the dialog, it blocks the rest of the application until the user has chosen a file.
Window.show()
, Serialized FormDialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType
Window.AccessibleAWTWindow, Window.Type
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
public static final int LOAD
This constant value indicates that the purpose of the file dialog window is to locate a file from which to read.
public static final int SAVE
This constant value indicates that the purpose of the file dialog window is to locate a file to which to write.
public FileDialog(Frame parent)
Creates a file dialog for loading a file. The title of the file dialog is initially empty. This is a convenience method for FileDialog(parent, "", LOAD)
.
parent
- the owner of the dialogpublic FileDialog(Frame parent, String title)
Creates a file dialog window with the specified title for loading a file. The files shown are those in the current directory. This is a convenience method for FileDialog(parent, title, LOAD)
.
parent
- the owner of the dialogtitle
- the title of the dialogpublic FileDialog(Frame parent, String title, int mode)
Creates a file dialog window with the specified title for loading or saving a file.
If the value of mode
is LOAD
, then the file dialog is finding a file to read, and the files shown are those in the current directory. If the value of mode
is SAVE
, the file dialog is finding a place to write a file.
parent
- the owner of the dialogtitle
- the title of the dialogmode
- the mode of the dialog; either FileDialog.LOAD
or FileDialog.SAVE
IllegalArgumentException
- if an illegal file dialog mode is suppliedLOAD
, SAVE
public FileDialog(Dialog parent)
Creates a file dialog for loading a file. The title of the file dialog is initially empty. This is a convenience method for FileDialog(parent, "", LOAD)
.
parent
- the owner of the dialogIllegalArgumentException
- if the parent
's GraphicsConfiguration
is not from a screen device;IllegalArgumentException
- if parent
is null
; this exception is always thrown when GraphicsEnvironment.isHeadless
returns true
GraphicsEnvironment.isHeadless()
public FileDialog(Dialog parent, String title)
Creates a file dialog window with the specified title for loading a file. The files shown are those in the current directory. This is a convenience method for FileDialog(parent, title, LOAD)
.
parent
- the owner of the dialogtitle
- the title of the dialog; a null
value will be accepted without causing a NullPointerException
to be thrownIllegalArgumentException
- if the parent
's GraphicsConfiguration
is not from a screen device;IllegalArgumentException
- if parent
is null
; this exception is always thrown when GraphicsEnvironment.isHeadless
returns true
GraphicsEnvironment.isHeadless()
public FileDialog(Dialog parent, String title, int mode)
Creates a file dialog window with the specified title for loading or saving a file.
If the value of mode
is LOAD
, then the file dialog is finding a file to read, and the files shown are those in the current directory. If the value of mode
is SAVE
, the file dialog is finding a place to write a file.
parent
- the owner of the dialogtitle
- the title of the dialog; a null
value will be accepted without causing a NullPointerException
to be thrownmode
- the mode of the dialog; either FileDialog.LOAD
or FileDialog.SAVE
IllegalArgumentException
- if an illegal file dialog mode is supplied;IllegalArgumentException
- if the parent
's GraphicsConfiguration
is not from a screen device;IllegalArgumentException
- if parent
is null
; this exception is always thrown when GraphicsEnvironment.isHeadless
returns true
GraphicsEnvironment.isHeadless()
, LOAD
, SAVE
public void addNotify()
Creates the file dialog's peer. The peer allows us to change the look of the file dialog without changing its functionality.
addNotify
in class Dialog
Component.isDisplayable()
, Window.removeNotify()
public int getMode()
Indicates whether this file dialog box is for loading from a file or for saving to a file.
FileDialog.LOAD
or FileDialog.SAVE
LOAD
, SAVE
, setMode(int)
public void setMode(int mode)
Sets the mode of the file dialog. If mode
is not a legal value, an exception will be thrown and mode
will not be set.
mode
- the mode for this file dialog, either FileDialog.LOAD
or FileDialog.SAVE
IllegalArgumentException
- if an illegal file dialog mode is suppliedLOAD
, SAVE
, getMode()
public String getDirectory()
Gets the directory of this file dialog.
null
or invalid) directory of this FileDialog
setDirectory(java.lang.String)
public void setDirectory(String dir)
Sets the directory of this file dialog window to be the specified directory. Specifying a null
or an invalid directory implies an implementation-defined default. This default will not be realized, however, until the user has selected a file. Until this point, getDirectory()
will return the value passed into this method.
Specifying "" as the directory is exactly equivalent to specifying null
as the directory.
dir
- the specified directorygetDirectory()
public String getFile()
Gets the selected file of this file dialog. If the user selected CANCEL
, the returned file is null
.
null
if none is selectedsetFile(java.lang.String)
public File[] getFiles()
Returns files that the user selects.
If the user cancels the file dialog, then the method returns an empty array.
setFile(String)
, getFile()
public void setFile(String file)
Sets the selected file for this file dialog window to be the specified file. This file becomes the default file if it is set before the file dialog window is first shown.
When the dialog is shown, the specified file is selected. The kind of selection depends on the file existence, the dialog type, and the native platform. E.g., the file could be highlighted in the file list, or a file name editbox could be populated with the file name.
This method accepts either a full file path, or a file name with an extension if used together with the setDirectory
method.
Specifying "" as the file is exactly equivalent to specifying null
as the file.
file
- the file being setgetFile()
, getFiles()
public void setMultipleMode(boolean enable)
Enables or disables multiple file selection for the file dialog.
enable
- if true
, multiple file selection is enabled; false
- disabled.isMultipleMode()
public boolean isMultipleMode()
Returns whether the file dialog allows the multiple file selection.
true
if the file dialog allows the multiple file selection; false
otherwise.setMultipleMode(boolean)
public FilenameFilter getFilenameFilter()
Determines this file dialog's filename filter. A filename filter allows the user to specify which files appear in the file dialog window. Filename filters do not function in Sun's reference implementation for Microsoft Windows.
FilenameFilter
, setFilenameFilter(java.io.FilenameFilter)
public void setFilenameFilter(FilenameFilter filter)
Sets the filename filter for this file dialog window to the specified filter. Filename filters do not function in Sun's reference implementation for Microsoft Windows.
filter
- the specified filterFilenameFilter
, getFilenameFilter()
protected String paramString()
Returns a string representing the state of this FileDialog
window. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null
.
paramString
in class Dialog
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.