- All Implemented Interfaces:
- ImageObserver,- MenuContainer,- Serializable,- Accessible
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:
- 1.0
- See Also:
- 
Nested Class SummaryNested classes/interfaces declared in class java.awt.DialogDialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityTypeNested classes/interfaces declared in class java.awt.WindowWindow.AccessibleAWTWindow, Window.TypeNested classes/interfaces declared in class java.awt.ContainerContainer.AccessibleAWTContainerNested classes/interfaces declared in class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThis constant value indicates that the purpose of the file dialog window is to locate a file from which to read.static final intThis constant value indicates that the purpose of the file dialog window is to locate a file to which to write.Fields declared in class java.awt.DialogDEFAULT_MODALITY_TYPEFields declared in class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
- 
Constructor SummaryConstructorsConstructorDescriptionFileDialog(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.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 SummaryModifier and TypeMethodDescriptionvoidCreates the file dialog's peer.Gets the directory of this file dialog.getFile()Gets the selected file of this file dialog.Determines this file dialog's filename filter.File[]getFiles()Returns files that the user selects.intgetMode()Indicates whether this file dialog box is for loading from a file or for saving to a file.booleanReturns whether the file dialog allows the multiple file selection.protected StringReturns a string representing the state of thisFileDialogwindow.voidsetDirectory(String dir) Sets the directory of this file dialog window to be the specified directory.voidSets the selected file for this file dialog window to be the specified file.voidsetFilenameFilter(FilenameFilter filter) Sets the filename filter for this file dialog window to the specified filter.voidsetMode(int mode) Sets the mode of the file dialog.voidsetMultipleMode(boolean enable) Enables or disables multiple file selection for the file dialog.voidSets the title of the Dialog.Methods declared in class java.awt.DialoggetAccessibleContext, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setUndecorated, setVisible, show, toBackMethods declared in class java.awt.WindowaddPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBackground, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setOpacity, setShape, setSize, setSize, setType, toFrontMethods declared in class java.awt.Containeradd, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTreeMethods declared in class java.awt.Componentaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
- 
Field Details- 
LOADpublic static final int LOADThis constant value indicates that the purpose of the file dialog window is to locate a file from which to read.- See Also:
 
- 
SAVEpublic static final int SAVEThis constant value indicates that the purpose of the file dialog window is to locate a file to which to write.- See Also:
 
 
- 
- 
Constructor Details- 
FileDialogCreates a file dialog for loading a file. The title of the file dialog is initially empty. This is a convenience method forFileDialog(parent, "", LOAD).Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. - Parameters:
- parent- the owner of the dialog
- Since:
- 1.1
 
- 
FileDialogCreates 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 forFileDialog(parent, title, LOAD).Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. - Parameters:
- parent- the owner of the dialog
- title- the title of the dialog
 
- 
FileDialogCreates a file dialog window with the specified title for loading or saving a file.If the value of modeisLOAD, then the file dialog is finding a file to read, and the files shown are those in the current directory. If the value ofmodeisSAVE, the file dialog is finding a place to write a file.Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. - Parameters:
- parent- the owner of the dialog
- title- the title of the dialog
- mode- the mode of the dialog; either- FileDialog.LOADor- FileDialog.SAVE
- Throws:
- IllegalArgumentException- if an illegal file dialog mode is supplied
- See Also:
 
- 
FileDialogCreates a file dialog for loading a file. The title of the file dialog is initially empty. This is a convenience method forFileDialog(parent, "", LOAD).Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. - Parameters:
- parent- the owner of the dialog
- Throws:
- IllegalArgumentException- if the- parent's- GraphicsConfigurationis not from a screen device;
- IllegalArgumentException- if- parentis- null; this exception is always thrown when- GraphicsEnvironment.isHeadlessreturns- true
- Since:
- 1.5
- See Also:
 
- 
FileDialogCreates 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 forFileDialog(parent, title, LOAD).Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. - Parameters:
- parent- the owner of the dialog
- title- the title of the dialog; a- nullvalue will be accepted without causing a- NullPointerExceptionto be thrown
- Throws:
- IllegalArgumentException- if the- parent's- GraphicsConfigurationis not from a screen device;
- IllegalArgumentException- if- parentis- null; this exception is always thrown when- GraphicsEnvironment.isHeadlessreturns- true
- Since:
- 1.5
- See Also:
 
- 
FileDialogCreates a file dialog window with the specified title for loading or saving a file.If the value of modeisLOAD, then the file dialog is finding a file to read, and the files shown are those in the current directory. If the value ofmodeisSAVE, the file dialog is finding a place to write a file.Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. - Parameters:
- parent- the owner of the dialog
- title- the title of the dialog; a- nullvalue will be accepted without causing a- NullPointerExceptionto be thrown
- mode- the mode of the dialog; either- FileDialog.LOADor- FileDialog.SAVE
- Throws:
- IllegalArgumentException- if an illegal file dialog mode is supplied;
- IllegalArgumentException- if the- parent's- GraphicsConfigurationis not from a screen device;
- IllegalArgumentException- if- parentis- null; this exception is always thrown when- GraphicsEnvironment.isHeadlessreturns- true
- Since:
- 1.5
- See Also:
 
 
- 
- 
Method Details- 
setTitleSets the title of the Dialog.Note: Some platforms may not support showing the user-specified title in a file dialog. In this situation, either no title will be displayed in the file dialog's title bar or, on some systems, the file dialog's title bar will not be displayed. 
- 
addNotifypublic void addNotify()Creates the file dialog's peer. The peer allows us to change the look of the file dialog without changing its functionality.
- 
getModepublic 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.LOADorFileDialog.SAVE
- See Also:
 
- 
setModepublic void setMode(int mode) Sets the mode of the file dialog. Ifmodeis not a legal value, an exception will be thrown andmodewill not be set.- Parameters:
- mode- the mode for this file dialog, either- FileDialog.LOADor- FileDialog.SAVE
- Throws:
- IllegalArgumentException- if an illegal file dialog mode is supplied
- Since:
- 1.1
- See Also:
 
- 
getDirectoryGets the directory of this file dialog.- Returns:
- the (potentially nullor invalid) directory of thisFileDialog
- See Also:
 
- 
setDirectorySets the directory of this file dialog window to be the specified directory. Specifying anullor 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 nullas the directory.- Parameters:
- dir- the specified directory
- See Also:
 
- 
getFileGets the selected file of this file dialog. If the user selectedCANCEL, the returned file isnull.- Returns:
- the currently selected file of this file dialog window,
                or nullif none is selected
- See Also:
 
- 
getFilesReturns files that the user selects.If the user cancels the file dialog, then the method returns an empty array. - Returns:
- files that the user selects or an empty array if the user cancels the file dialog.
- Since:
- 1.7
- See Also:
 
- 
setFileSets 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 setDirectorymethod.Specifying "" as the file is exactly equivalent to specifying nullas the file.- Parameters:
- file- the file being set
- See Also:
 
- 
setMultipleModepublic void setMultipleMode(boolean enable) Enables or disables multiple file selection for the file dialog.- Parameters:
- enable- if- true, multiple file selection is enabled;- false- disabled.
- Since:
- 1.7
- See Also:
 
- 
isMultipleModepublic boolean isMultipleMode()Returns whether the file dialog allows the multiple file selection.- Returns:
- trueif the file dialog allows the multiple file selection;- falseotherwise.
- Since:
- 1.7
- See Also:
 
- 
getFilenameFilterDetermines 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
- See Also:
 
- 
setFilenameFilterSets 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
- See Also:
 
- 
paramStringReturns a string representing the state of thisFileDialogwindow. 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 benull.- Overrides:
- paramStringin class- Dialog
- Returns:
- the parameter string of this file dialog window
 
 
-