- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.Window
-
- java.awt.Dialog
-
- java.awt.FileDialog
-
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible
public class FileDialog extends Dialog
TheFileDialog
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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType
-
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field and Description 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.Dialog
DEFAULT_MODALITY_TYPE
-
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor and Description 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.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
Methods Modifier and Type Method and Description 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.File[]
getFiles()
Returns files that the user selects.int
getMode()
Indicates whether this file dialog box is for loading from a file or for saving to a file.boolean
isMultipleMode()
Returns whether the file dialog allows the multiple file selection.protected String
paramString()
Returns a string representing the state of thisFileDialog
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.void
setMultipleMode(boolean enable)
Enables or disables multiple file selection for the file dialog.-
Methods inherited from class java.awt.Dialog
getAccessibleContext, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, setVisible, show, toBack
-
Methods inherited from class java.awt.Window
addPropertyChangeListener, 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, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFront
-
Methods inherited from class java.awt.Container
add, 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, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree
-
Methods inherited from class java.awt.Component
action, 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, getPeer, 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, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
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.- See Also:
- Constant Field Values
-
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.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileDialog
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 forFileDialog(parent, "", LOAD)
.- 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. This is a convenience method forFileDialog(parent, title, LOAD)
.- Parameters:
parent
- the owner of the dialogtitle
- 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
isLOAD
, then the file dialog is finding a file to read, and the files shown are those in the current directory. If the value ofmode
isSAVE
, the file dialog is finding a place to write a file.- Parameters:
parent
- the owner of the dialogtitle
- the title of the dialogmode
- the mode of the dialog; eitherFileDialog.LOAD
orFileDialog.SAVE
- Throws:
IllegalArgumentException
- if an illegal file dialog mode is supplied- See Also:
LOAD
,SAVE
-
FileDialog
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 forFileDialog(parent, "", LOAD)
.- Parameters:
parent
- the owner of the dialog- Throws:
IllegalArgumentException
- if theparent
'sGraphicsConfiguration
is not from a screen device;IllegalArgumentException
- ifparent
isnull
; this exception is always thrown whenGraphicsEnvironment.isHeadless
returnstrue
- Since:
- 1.5
- See Also:
GraphicsEnvironment.isHeadless()
-
FileDialog
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 forFileDialog(parent, title, LOAD)
.- Parameters:
parent
- the owner of the dialogtitle
- the title of the dialog; anull
value will be accepted without causing aNullPointerException
to be thrown- Throws:
IllegalArgumentException
- if theparent
'sGraphicsConfiguration
is not from a screen device;IllegalArgumentException
- ifparent
isnull
; this exception is always thrown whenGraphicsEnvironment.isHeadless
returnstrue
- Since:
- 1.5
- See Also:
GraphicsEnvironment.isHeadless()
-
FileDialog
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
isLOAD
, then the file dialog is finding a file to read, and the files shown are those in the current directory. If the value ofmode
isSAVE
, the file dialog is finding a place to write a file.- Parameters:
parent
- the owner of the dialogtitle
- the title of the dialog; anull
value will be accepted without causing aNullPointerException
to be thrownmode
- the mode of the dialog; eitherFileDialog.LOAD
orFileDialog.SAVE
- Throws:
IllegalArgumentException
- if an illegal file dialog mode is supplied;IllegalArgumentException
- if theparent
'sGraphicsConfiguration
is not from a screen device;IllegalArgumentException
- ifparent
isnull
; this exception is always thrown whenGraphicsEnvironment.isHeadless
returnstrue
- Since:
- 1.5
- See Also:
GraphicsEnvironment.isHeadless()
,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 classDialog
- See Also:
Component.isDisplayable()
,Window.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
orFileDialog.SAVE
- See Also:
LOAD
,SAVE
,setMode(int)
-
setMode
public void setMode(int mode)
Sets the mode of the file dialog. Ifmode
is not a legal value, an exception will be thrown andmode
will not be set.- Parameters:
mode
- the mode for this file dialog, eitherFileDialog.LOAD
orFileDialog.SAVE
- Throws:
IllegalArgumentException
- if an illegal file dialog mode is supplied- 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 thisFileDialog
- 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 anull
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:
getDirectory()
-
getFile
public String getFile()
Gets 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
null
if none is selected - See Also:
setFile(java.lang.String)
-
getFiles
public File[] getFiles()
Returns 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:
setFile(String)
,getFile()
-
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()
,getFiles()
-
setMultipleMode
public void setMultipleMode(boolean enable)
Enables or disables multiple file selection for the file dialog.- Parameters:
enable
- iftrue
, multiple file selection is enabled;false
- disabled.- Since:
- 1.7
- See Also:
isMultipleMode()
-
isMultipleMode
public boolean isMultipleMode()
Returns whether the file dialog allows the multiple file selection.- Returns:
true
if the file dialog allows the multiple file selection;false
otherwise.- Since:
- 1.7
- See Also:
setMultipleMode(boolean)
-
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 Microsoft Windows.- 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 Microsoft Windows.- Parameters:
filter
- the specified filter- See Also:
FilenameFilter
,getFilenameFilter()
-
paramString
protected String paramString()
Returns a string representing the state of thisFileDialog
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 benull
.- Overrides:
paramString
in classDialog
- Returns:
- the parameter string of this file dialog window
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-java/awt/filedialog.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.