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.