JavaTM 2 Platform
Std. Ed. v1.3

java.awt
Class FileDialog

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--java.awt.FileDialog
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

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.

Since:
JDK1.0
See Also:
Window.show(), Serialized Form

Inner classes inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
Inner classes inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
static int LOAD
          This constant value indicates that the purpose of the file dialog window is to locate a file from which to read.
static int SAVE
          This constant value indicates that the purpose of the file dialog window is to locate a file to which to write.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
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.
 
Method Summary
 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.
protected  String paramString()
          Returns the parameter string representing the state of this file dialog window.
 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.
 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.
 
Methods inherited from class java.awt.Dialog
dispose, getAccessibleContext, getTitle, hide, isModal, isResizable, setModal, setResizable, setTitle, show
 
Methods inherited from class java.awt.Window
addWindowListener, applyResourceBundle, applyResourceBundle, finalize, getFocusOwner, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, isShowing, pack, postEvent, processEvent, processWindowEvent, removeWindowListener, setCursor, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOAD

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.

SAVE

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.
Constructor Detail

FileDialog

public FileDialog(Frame parent)
Creates a file dialog for loading a file. The title of the file dialog is initially empty.
Parameters:
parent - the owner of the dialog
Since:
JDK1.1

FileDialog

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.
Parameters:
parent - the owner of the dialog.
title - the title of the dialog.

FileDialog

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. 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.
See Also:
LOAD, SAVE
Method Detail

addNotify

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.
Overrides:
addNotify in class Dialog
Following copied from class: java.awt.Dialog
See Also:
Component.isDisplayable(), Container.removeNotify()

getMode

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.
See Also:
LOAD, SAVE, setMode(int)

setMode

public void setMode(int mode)
Sets the mode of the file dialog.
Parameters:
mode - the mode for this file dialog, either FileDialog.LOAD or FileDialog.SAVE.
Throws:
IllegalArgumentException - if an illegal file dialog mode is used.
Since:
JDK1.1
See Also:
LOAD, SAVE, getMode()

getDirectory

public String getDirectory()
Gets the directory of this file dialog.
Returns:
the (potentially null or invalid) directory of this FileDialog.
See Also:
setDirectory(java.lang.String)

setDirectory

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 specific directory.
See Also:
getDirectory()

getFile

public String getFile()
Gets the selected file of this file dialog.
Returns:
the currently selected file of this file dialog window, or null if none is selected.
See Also:
setFile(java.lang.String)

setFile

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:
getFile()

getFilenameFilter

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 Windows 95, 98, or NT 4.0.
Returns:
this file dialog's filename filter.
See Also:
FilenameFilter, setFilenameFilter(java.io.FilenameFilter)

setFilenameFilter

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 Windows 95, 98, or NT 4.0.
Parameters:
filter - the specified filter.
See Also:
FilenameFilter, getFilenameFilter()

paramString

protected String paramString()
Returns the parameter string representing the state of this file dialog window. This string is useful for debugging.
Overrides:
paramString in class Dialog
Returns:
the parameter string of this file dialog window.

JavaTM 2 Platform
Std. Ed. v1.3

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.