public class FileDialog extends Dialog
FileDialog类显示一个对话框,用户可以选择一个文件。
因为它是一个模态对话框,当应用程序调用它的show方法显示的对话框,它会阻止其他应用程序在用户选择一个文件。
Window.show(),
Serialized Form
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityTypeWindow.AccessibleAWTWindow, Window.TypeContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static int |
LOAD
这个常量值表示“文件”对话框窗口的目的是找到一个从中读取的文件。
|
static int |
SAVE
这个常量值表示“文件”对话框窗口的目的是找到一个要写入的文件。
|
DEFAULT_MODALITY_TYPEaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
FileDialog(Dialog parent)
创建一个加载文件的文件对话框。
|
FileDialog(Dialog parent, String title)
用指定的标题创建一个文件对话框以加载文件。
|
FileDialog(Dialog parent, String title, int mode)
创建一个具有指定标题的文件对话框,用于加载或保存文件。
|
FileDialog(Frame parent)
创建一个加载文件的文件对话框。
|
FileDialog(Frame parent, String title)
用指定的标题创建一个文件对话框以加载文件。
|
FileDialog(Frame parent, String title, int mode)
创建一个具有指定标题的文件对话框,用于加载或保存文件。
|
| Modifier and Type | Method and Description |
|---|---|
void |
addNotify()
创建文件对话框的对等点。
|
String |
getDirectory()
获取此文件对话框的目录。
|
String |
getFile()
获取此文件对话框的选定文件。
|
FilenameFilter |
getFilenameFilter()
确定此文件对话框的文件名筛选器。
|
File[] |
getFiles()
返回用户选择的文件。
|
int |
getMode()
指示此文件对话框是否为从文件加载或保存到文件中。
|
boolean |
isMultipleMode()
返回文件对话框是否允许多个文件选择。
|
protected String |
paramString()
返回一个字符串,表示此
FileDialog窗口状态。
|
void |
setDirectory(String dir)
将此文件对话框的目录设置为指定的目录。
|
void |
setFile(String file)
将此文件对话框窗口的选定文件为指定的文件。
|
void |
setFilenameFilter(FilenameFilter filter)
将此文件对话框的文件名筛选器设置为指定的筛选器。
|
void |
setMode(int mode)
设置文件对话框的模式。
|
void |
setMultipleMode(boolean enable)
启用或禁用文件对话框的多个文件选择。
|
getAccessibleContext, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, setVisible, show, toBackaddPropertyChangeListener, 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, toFrontadd, 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, validateTreeaction, 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, transferFocusUpCyclepublic static final int LOAD
public static final int SAVE
public FileDialog(Frame parent)
FileDialog(parent, "", LOAD)便利的方法。
parent -该对话框的所有者
public FileDialog(Frame parent, String title)
FileDialog(parent, title, LOAD)便利的方法。
parent -该对话框的所有者
title -对话框的标题
public FileDialog(Frame parent, String title, int mode)
如果mode值LOAD文件对话框,然后找到一个文件的读取,显示的文件在当前目录。如果mode值SAVE文件对话框,找到一个地方写一个文件。
parent -该对话框的所有者
title -对话框的标题
mode -对话框的模式;要么
FileDialog.LOAD或
FileDialog.SAVE
IllegalArgumentException -如果提供非法文件对话框模式
LOAD,
SAVE
public FileDialog(Dialog parent)
FileDialog(parent, "", LOAD)便利的方法。
parent -该对话框的所有者
IllegalArgumentException -如果
parent的
GraphicsConfiguration不是从一个屏幕的设备;
IllegalArgumentException -如果
parent是
null;这种例外总是扔在
GraphicsEnvironment.isHeadless返回
true
GraphicsEnvironment.isHeadless()
public FileDialog(Dialog parent, String title)
FileDialog(parent, title, LOAD)便利的方法。
parent -该对话框的所有者
title -对话框的标题;一个
null值将不会造成
NullPointerException被接受
IllegalArgumentException -如果
parent的
GraphicsConfiguration不是从一个屏幕的设备;
IllegalArgumentException -如果
parent是
null;这种例外总是扔在
GraphicsEnvironment.isHeadless返回
true
GraphicsEnvironment.isHeadless()
public FileDialog(Dialog parent, String title, int mode)
如果mode值LOAD文件对话框,然后找到一个文件的读取,显示的文件在当前目录。如果mode值SAVE文件对话框,找到一个地方写一个文件。
parent -该对话框的所有者
title -对话框的标题;一个
null值将不会造成
NullPointerException被接受
mode -对话框的模式;要么
FileDialog.LOAD或
FileDialog.SAVE
IllegalArgumentException -如果提供非法文件对话框模式;
IllegalArgumentException -如果
parent的
GraphicsConfiguration不是从一个屏幕的设备;
IllegalArgumentException -如果
parent是
null;这种例外总是扔在
GraphicsEnvironment.isHeadless返回
true
GraphicsEnvironment.isHeadless(),
LOAD,
SAVE
public void addNotify()
addNotify 方法重写,继承类
Dialog
Component.isDisplayable(),
Window.removeNotify()
public int getMode()
FileDialog.LOAD或
FileDialog.SAVE
LOAD,
SAVE,
setMode(int)
public void setMode(int mode)
mode不是法律价值,将抛出一个异常,
mode将不会设置。
mode -该文件对话框的模式,无论是
FileDialog.LOAD或
FileDialog.SAVE
IllegalArgumentException -如果提供非法文件对话框模式
LOAD,
SAVE,
getMode()
public String getDirectory()
null或无效)这
FileDialog目录
setDirectory(java.lang.String)
public void setDirectory(String dir)
null或无效的目录是由实现定义的默认。此默认将不会实现,但是,直到用户选择了一个文件。直到此时,
getDirectory()将返回传递给这个方法的价值。
指定“”的目录是完全等同于指定的目录null。
dir -指定的目录
getDirectory()
public String getFile()
CANCEL,返回的文件
null。
null如果没有选择
setFile(java.lang.String)
public File[] getFiles()
如果用户取消了文件对话框,则该方法返回一个空数组。
setFile(String),
getFile()
public void setFile(String file)
当显示对话框时,选择指定的文件。该类型的选择取决于文件的存在、对话框类型和本地平台的类型。例如,文件可以在文件列表中突出显示,或文件名编辑框可以填入文件名。
这个方法接受一个完整的文件路径或文件名和扩展如果与setDirectory方法一起使用。
指定“”的文件是完全等同于指定的文件null。
file -设置文件
getFile(),
getFiles()
public void setMultipleMode(boolean enable)
enable -如果
true,选择多个文件启用;
false残疾。
isMultipleMode()
public boolean isMultipleMode()
true如果文件对话框允许选择多个文件;
false否则。
setMultipleMode(boolean)
public FilenameFilter getFilenameFilter()
FilenameFilter,
setFilenameFilter(java.io.FilenameFilter)
public void setFilenameFilter(FilenameFilter filter)
filter -指定的过滤器
FilenameFilter,
getFilenameFilter()
protected String paramString()
FileDialog窗口状态。此方法仅用于调试目的,返回的字符串的内容和格式可能会在实现过程中有所不同。返回的字符串是空的但可能不
null。
paramString 方法重写,继承类
Dialog
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.