FileDialog (Java 2 Platform SE 5.0) (original) (raw)
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:
ImageObserver, MenuContainer, Serializable, Accessible
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
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Dialog |
---|
Dialog.AccessibleAWTDialog |
Nested classes/interfaces inherited from class java.awt.Window |
---|
Window.AccessibleAWTWindow |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
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(Dialog parent) Creates a file dialog for loading a file. |
[FileDialog](../../java/awt/FileDialog.html#FileDialog%28java.awt.Dialog, java.lang.String%29)(Dialog parent,String title) Creates a file dialog window with the specified title for loading a file. |
[FileDialog](../../java/awt/FileDialog.html#FileDialog%28java.awt.Dialog, java.lang.String, int%29)(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](../../java/awt/FileDialog.html#FileDialog%28java.awt.Frame, java.lang.String%29)(Frame parent,String title) Creates a file dialog window with the specified title for loading a file. |
[FileDialog](../../java/awt/FileDialog.html#FileDialog%28java.awt.Frame, java.lang.String, int%29)(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 a string representing the state of this FileDialog 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 |
---|
getAccessibleContext, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show |
Methods inherited from class java.awt.Container |
---|
add, [add](../../java/awt/Container.html#add%28java.awt.Component, int%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object, int%29), [add](../../java/awt/Container.html#add%28java.lang.String, java.awt.Component%29), addContainerListener, [addImpl](../../java/awt/Container.html#addImpl%28java.awt.Component, java.lang.Object, int%29), applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, [findComponentAt](../../java/awt/Container.html#findComponentAt%28int, int%29), findComponentAt, getAlignmentX, getAlignmentY, getComponent, [getComponentAt](../../java/awt/Container.html#getComponentAt%28int, int%29), getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, [list](../../java/awt/Container.html#list%28java.io.PrintStream, int%29), [list](../../java/awt/Container.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Container.html#locate%28int, int%29), minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, [setComponentZOrder](../../java/awt/Container.html#setComponentZOrder%28java.awt.Component, int%29), [setFocusTraversalKeys](../../java/awt/Container.html#setFocusTraversalKeys%28int, java.util.Set%29), setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), [contains](../../java/awt/Component.html#contains%28int, int%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, int, int%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, 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](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29), [inside](../../java/awt/Component.html#inside%28int, int%29), isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), list, list, list, location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paintAll, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, [repaint](../../java/awt/Component.html#repaint%28long, int, int, int, int%29), requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, [reshape](../../java/awt/Component.html#reshape%28int, int, int, int%29), resize, [resize](../../java/awt/Component.html#resize%28int, int%29), setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), setVisible, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
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:
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:
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 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, and the files shown are those in the current directory. If the value ofmode
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; eitherFileDialog.LOAD
or FileDialog.SAVE
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if an illegal file dialog mode is supplied
See Also:
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](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the parent
'sGraphicsConfiguration
is not from a screen device;
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if parent
is null
; this exception is always thrown whenGraphicsEnvironment.isHeadless
returns true
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 dialog
title
- the title of the dialog; a null
value will be accepted without causing aNullPointerException
to be thrown
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the parent
'sGraphicsConfiguration
is not from a screen device;
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if parent
is null
; this exception is always thrown whenGraphicsEnvironment.isHeadless
returns true
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
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 ofmode
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 aNullPointerException
to be thrown
mode
- the mode of the dialog; eitherFileDialog.LOAD
or FileDialog.SAVE
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if an illegal file dialog mode is supplied;
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the parent
'sGraphicsConfiguration
is not from a screen device;
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if parent
is null
; this exception is always thrown whenGraphicsEnvironment.isHeadless
returns true
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](../../java/awt/Dialog.html#addNotify%28%29)
in class [Dialog](../../java/awt/Dialog.html "class in java.awt")
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, eitherFileDialog.LOAD
orFileDialog.SAVE
See Also:
setMode
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, eitherFileDialog.LOAD
orFileDialog.SAVE
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if an illegal file dialog mode is supplied
Since:
JDK1.1
See Also:
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 specified directory
See Also:
getFile
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:
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 specifyingnull
as the file.
Parameters:
file
- the file being set
See Also:
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 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
.
Overrides:
[paramString](../../java/awt/Dialog.html#paramString%28%29)
in class [Dialog](../../java/awt/Dialog.html "class in java.awt")
Returns:
the parameter string of this file dialog window
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.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.