public class

FileDialog

extends Dialog
java.lang.Object
   ↳ java.awt.Component
     ↳ java.awt.Container
       ↳ java.awt.Window
         ↳ java.awt.Dialog
           ↳ java.awt.FileDialog

Class Overview

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.

See Also

Summary

Constants
int LOAD This constant value indicates that the purpose of the file dialog window is to locate a file from which to read.
int SAVE This constant value indicates that the purpose of the file dialog window is to locate a file to which to write.
[Expand]
Inherited Constants
From class java.awt.Component
From interface java.awt.image.ImageObserver
[Expand]
Inherited Fields
From class java.awt.Dialog
Public Constructors
FileDialog(Frame parent)
Creates a file dialog for loading a file.
FileDialog(Frame parent, String title)
Creates a file dialog window with the specified title for loading a file.
FileDialog(Frame parent, String title, int mode)
Creates a file dialog window with the specified title for loading or saving a file.
FileDialog(Dialog parent)
Creates a file dialog for loading a file.
FileDialog(Dialog parent, String title)
Creates a file dialog window with the specified title for loading a file.
FileDialog(Dialog parent, String title, int mode)
Creates a file dialog window with the specified title for loading or saving a file.
Public Methods
void addNotify()
Creates the file dialog's peer.
String getDirectory()
Gets the directory of this file dialog.
String getFile()
Gets the selected file of this file dialog.
FilenameFilter getFilenameFilter()
Determines this file dialog's filename filter.
int getMode()
Indicates whether this file dialog box is for loading from a file or for saving to a file.
void setDirectory(String dir)
Sets the directory of this file dialog window to be the specified directory.
void setFile(String file)
Sets the selected file for this file dialog window to be the specified file.
synchronized void setFilenameFilter(FilenameFilter filter)
Sets the filename filter for this file dialog window to the specified filter.
void setMode(int mode)
Sets the mode of the file dialog.
Protected Methods
String paramString()
Returns a string representing the state of this FileDialog window.
[Expand]
Inherited Methods
From class java.awt.Dialog
From class java.awt.Window
From class java.awt.Container
From class java.awt.Component
From class java.lang.Object
From interface java.awt.MenuContainer
From interface java.awt.image.ImageObserver
From interface javax.accessibility.Accessible

Constants

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.

Constant Value: 0 (0x00000000)

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.

Constant Value: 1 (0x00000001)

Public Constructors

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).

Parameters
parent the owner of the dialog

public 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).

Parameters
parent the owner of the dialog
title the title of the dialog

public 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.

Parameters
parent the owner of the dialog
title the title of the dialog
mode the mode of the dialog; either FileDialog.LOAD or FileDialog.SAVE
Throws
IllegalArgumentException if an illegal file dialog mode is supplied
See Also

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).

Parameters
parent the owner of the dialog
Throws
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
See Also

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).

Parameters
parent the owner of the dialog
title the title of the dialog; a null value will be accepted without causing a NullPointerException to be thrown
Throws
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
See Also

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.

Parameters
parent the owner of the dialog
title the title of the dialog; a null value will be accepted without causing a NullPointerException to be thrown
mode the mode of the dialog; either FileDialog.LOAD or FileDialog.SAVE
Throws
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

Public Methods

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.

public String getDirectory ()

Gets the directory of this file dialog.

Returns
  • the (potentially null or invalid) directory of this FileDialog

public String getFile ()

Gets the selected file of this file dialog. If the user selected CANCEL, the returned file is null.

Returns
  • the currently selected file of this file dialog window, or null if none is selected
See Also

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.

Returns
  • this file dialog's filename filter

public int getMode ()

Indicates whether this file dialog box is for loading from a file or for saving to a file.

Returns
  • the mode of this file dialog window, either FileDialog.LOAD or FileDialog.SAVE

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.

Parameters
dir the specified directory
See Also

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.

Specifying "" as the file is exactly equivalent to specifying null as the file.

Parameters
file the file being set
See Also

public synchronized 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.

Parameters
filter the specified filter

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.

Parameters
mode the mode for this file dialog, either FileDialog.LOAD or FileDialog.SAVE
Throws
IllegalArgumentException if an illegal file dialog mode is supplied

Protected Methods

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.

Returns
  • the parameter string of this file dialog window