public class JFileChooser extends JComponent implements Accessible
JFileChooser提供了一个简单的机制,供用户选择一个文件。
有关使用JFileChooser ,请参阅Java教程中的 How to Use File Choosers部分。
以下代码弹出用户主目录的文件选择器,仅查看.jpg和.gif图像:
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
| Modifier and Type | Class and Description |
|---|---|
protected class |
JFileChooser.AccessibleJFileChooser
这个类实现了可访问性支持
JFileChooser类。
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategylistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JFileChooser()
构造一个
JFileChooser指向用户的默认目录。
|
JFileChooser(File currentDirectory)
构造一个
JFileChooser使用给定的
File作为路径。
|
JFileChooser(File currentDirectory, FileSystemView fsv)
构造一个
JFileChooser使用给定的当前目录和
FileSystemView 。
|
JFileChooser(FileSystemView fsv)
构造一个
JFileChooser使用给定
FileSystemView 。
|
JFileChooser(String currentDirectoryPath)
使用给定的路径构造一个
JFileChooser 。
|
JFileChooser(String currentDirectoryPath, FileSystemView fsv)
构造一个
JFileChooser使用给定的当前目录路径和
FileSystemView 。
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(File f)
如果文件应该显示,则返回true。
|
void |
addActionListener(ActionListener l)
将
ActionListener添加到文件选择器。
|
void |
addChoosableFileFilter(FileFilter filter)
将一个过滤器添加到用户可选择的文件过滤器列表中。
|
void |
approveSelection()
当用户点击“批准”按钮(默认情况下标记为“打开”或“保存”)时,由用户名称调用。
|
void |
cancelSelection()
当用户选择“取消”按钮时,由UI调用。
|
void |
changeToParentDirectory()
将要设置的目录更改为当前目录的父级。
|
protected JDialog |
createDialog(Component parent)
创建并返回一个新的
JDialog封装
this集中在
parent的框架上的
parent 。
|
void |
ensureFileIsVisible(File f)
确保指定的文件是可见的,而不是隐藏。
|
protected void |
fireActionPerformed(String command)
通知所有在此事件类型上通知有兴趣的听众。
|
FileFilter |
getAcceptAllFileFilter()
返回
AcceptAll文件过滤器。
|
AccessibleContext |
getAccessibleContext()
获取与此JFileChooser关联的AccessibleContext。
|
JComponent |
getAccessory()
返回附件组件。
|
ActionListener[] |
getActionListeners()
返回在此文件选择器上注册的所有动作侦听器的数组。
|
int |
getApproveButtonMnemonic()
返回批准按钮的助记符。
|
String |
getApproveButtonText()
返回在使用的文本
ApproveButton在
FileChooserUI 。
|
String |
getApproveButtonToolTipText()
返回
ApproveButton使用的工具提示文本。
|
FileFilter[] |
getChoosableFileFilters()
获取用户可选择的文件过滤器列表。
|
boolean |
getControlButtonsAreShown()
返回
controlButtonsAreShown属性的值。
|
File |
getCurrentDirectory()
返回当前目录。
|
String |
getDescription(File f)
返回文件描述。
|
String |
getDialogTitle()
获取
JFileChooser的标题
JFileChooser的字符串。
|
int |
getDialogType()
返回此对话框的类型。
|
boolean |
getDragEnabled()
获取
dragEnabled属性的值。
|
FileFilter |
getFileFilter()
返回当前选择的文件过滤器。
|
int |
getFileSelectionMode()
返回当前的文件选择模式。
|
FileSystemView |
getFileSystemView()
返回文件系统视图。
|
FileView |
getFileView()
返回当前文件视图。
|
Icon |
getIcon(File f)
返回此文件或文件类型的图标,具体取决于系统。
|
String |
getName(File f)
返回文件名。
|
File |
getSelectedFile()
返回所选文件。
|
File[] |
getSelectedFiles()
如果文件选择器设置为允许多个选择,则返回所选文件的列表。
|
String |
getTypeDescription(File f)
返回文件类型。
|
FileChooserUI |
getUI()
获取实现此组件的L&F的UI对象。
|
String |
getUIClassID()
返回一个字符串,它指定呈现此组件的L&F类的名称。
|
boolean |
isAcceptAllFileFilterUsed()
返回是否使用
AcceptAll FileFilter 。
|
boolean |
isDirectorySelectionEnabled()
方便电话确定目录是否可以根据当前的文件选择模式进行选择。
|
boolean |
isFileHidingEnabled()
如果文件选择器中未显示隐藏文件,则返回true;
否则返回false。
|
boolean |
isFileSelectionEnabled()
方便电话确定文件是否可以基于当前文件选择模式进行选择。
|
boolean |
isMultiSelectionEnabled()
如果可以选择多个文件,则返回true。
|
boolean |
isTraversable(File f)
如果可以访问文件(目录),则返回true。
|
protected String |
paramString()
返回此
JFileChooser的字符串表示
JFileChooser 。
|
void |
removeActionListener(ActionListener l)
从文件选择器中删除一个
ActionListener 。
|
boolean |
removeChoosableFileFilter(FileFilter f)
从用户可选择的文件过滤器列表中删除一个过滤器。
|
void |
rescanCurrentDirectory()
告诉用户界面从当前目录重新扫描其文件列表。
|
void |
resetChoosableFileFilters()
将可选择的文件过滤器列表重置为其启动状态。
|
void |
setAcceptAllFileFilterUsed(boolean b)
确定是否
AcceptAll FileFilter用作可选择过滤器列表中一个可用选项。
|
void |
setAccessory(JComponent newAccessory)
设置附件组件。
|
void |
setApproveButtonMnemonic(char mnemonic)
使用字符设置批准按钮的助记符。
|
void |
setApproveButtonMnemonic(int mnemonic)
使用数字键码设置批准按钮的助记符。
|
void |
setApproveButtonText(String approveButtonText)
设置在使用的文本
ApproveButton在
FileChooserUI 。
|
void |
setApproveButtonToolTipText(String toolTipText)
设置
ApproveButton使用的工具提示文本。
|
void |
setControlButtonsAreShown(boolean b)
设置指示
批准和
取消按钮是否显示在文件选择器中的属性。
|
void |
setCurrentDirectory(File dir)
设置当前目录。
|
void |
setDialogTitle(String dialogTitle)
设置
JFileChooser窗口标题栏中的字符串。
|
void |
setDialogType(int dialogType)
设置此对话框的类型。
|
void |
setDragEnabled(boolean b)
设置
dragEnabled属性,该属性必须为
true以启用此组件上的自动拖放处理(第一部分拖放)。
|
void |
setFileFilter(FileFilter filter)
设置当前文件过滤器。
|
void |
setFileHidingEnabled(boolean b)
设置文件隐藏打开或关闭。
|
void |
setFileSelectionMode(int mode)
设置
JFileChooser以允许用户只需选择文件,只需选择目录,或选择文件和目录。
|
void |
setFileSystemView(FileSystemView fsv)
设置
JFileChooser用于访问和创建文件系统资源的文件系统视图,例如查找软盘驱动器和获取根驱动器列表。
|
void |
setFileView(FileView fileView)
设置用于检索UI信息的文件视图,例如表示文件的图标或文件的类型说明。
|
void |
setMultiSelectionEnabled(boolean b)
设置文件选择器以允许多个文件选择。
|
void |
setSelectedFile(File file)
设置所选文件。
|
void |
setSelectedFiles(File[] selectedFiles)
如果文件选择器设置为允许多个选择,则设置所选文件的列表。
|
protected void |
setup(FileSystemView view)
执行常见的构造函数初始化和设置。
|
int |
showDialog(Component parent, String approveButtonText)
使用自定义批准按钮弹出自定义文件选择器对话框。
|
int |
showOpenDialog(Component parent)
弹出一个“打开文件”文件选择器对话框。
|
int |
showSaveDialog(Component parent)
弹出“保存文件”文件选择器对话框。
|
void |
updateUI()
将UI属性重置为当前外观的值。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final int OPEN_DIALOG
JFileChooser支持“打开”文件操作。
public static final int SAVE_DIALOG
JFileChooser支持“保存”文件操作。
public static final int CUSTOM_DIALOG
JFileChooser支持开发人员指定的文件操作。
public static final int CANCEL_OPTION
public static final int APPROVE_OPTION
public static final int ERROR_OPTION
public static final int FILES_ONLY
public static final int DIRECTORIES_ONLY
public static final int FILES_AND_DIRECTORIES
public static final String CANCEL_SELECTION
public static final String APPROVE_SELECTION
public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
public static final String DIRECTORY_CHANGED_PROPERTY
public static final String SELECTED_FILE_CHANGED_PROPERTY
public static final String SELECTED_FILES_CHANGED_PROPERTY
public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
public static final String FILE_VIEW_CHANGED_PROPERTY
public static final String FILE_HIDING_CHANGED_PROPERTY
public static final String FILE_FILTER_CHANGED_PROPERTY
public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY
public static final String ACCESSORY_CHANGED_PROPERTY
public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
public static final String DIALOG_TITLE_CHANGED_PROPERTY
public static final String DIALOG_TYPE_CHANGED_PROPERTY
public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
protected AccessibleContext accessibleContext
public JFileChooser()
JFileChooser指向用户的默认目录。
这个默认值取决于操作系统。
它通常是Windows上的“我的文档”文件夹,Unix上的用户主目录。
public JFileChooser(String currentDirectoryPath)
JFileChooser 。
传递null字符串会导致文件选择器指向用户的默认目录。
这个默认值取决于操作系统。
它通常是Windows上的“我的文档”文件夹,Unix上的用户主目录。
currentDirectoryPath - a
String给出文件或目录的路径
public JFileChooser(File currentDirectory)
JFileChooser使用给定的File作为路径。
传递null文件会导致文件选择器指向用户的默认目录。
这个默认值取决于操作系统。
它通常是Windows上的“我的文档”文件夹,Unix上的用户主目录。
currentDirectory - 一个
File文件或目录的路径的
File对象
public JFileChooser(FileSystemView fsv)
JFileChooser使用给定的
FileSystemView 。
public JFileChooser(File currentDirectory, FileSystemView fsv)
JFileChooser使用给定的当前目录和
FileSystemView 。
public JFileChooser(String currentDirectoryPath, FileSystemView fsv)
JFileChooser使用给定的当前目录路径和
FileSystemView 。
protected void setup(FileSystemView view)
public void setDragEnabled(boolean b)
dragEnabled属性,该属性必须为true以启用此组件上的自动拖放处理(第一部分拖放)。
transferHandler属性需要设置为非null值来拖动才能执行任何操作。
dragEnabled属性的默认值为false 。
当启用自动拖动处理时,每当用户将鼠标按在一个项目上,然后将鼠标移动几个像素时,大多数外观和感觉开始拖放操作。 因此,将此属性设置为true可以对选择行为的方式产生微妙的影响。
有些外观和感觉可能不支持自动拖放; 他们将忽略此属性。 您可以解决这样的外观和修改组件以直接调用感觉exportAsDrag一个的方法TransferHandler 。
b - 设置
dragEnabled属性的值
HeadlessException - 如果
b是
true和
GraphicsEnvironment.isHeadless()返回
true
GraphicsEnvironment.isHeadless() , getDragEnabled() , JComponent.setTransferHandler(javax.swing.TransferHandler) , TransferHandler
public boolean getDragEnabled()
dragEnabled属性的值。
dragEnabled属性
setDragEnabled(boolean)
public File getSelectedFile()
setSelectedFile或用户操作设置,例如在UI中键入文件名或从UI中的列表中选择文件。
setSelectedFile(java.io.File)
public void setSelectedFile(File file)
file - 所选文件
getSelectedFile()
public File[] getSelectedFiles()
public void setSelectedFiles(File[] selectedFiles)
public File getCurrentDirectory()
setCurrentDirectory(java.io.File)
public void setCurrentDirectory(File dir)
null设置文件选择器指向用户的默认目录。
这个默认值取决于操作系统。
它通常是Windows上的“我的文档”文件夹,Unix上的用户主目录。
如果以currentDirectory传递的文件不是目录,则该文件的父项将被用作currentDirectory。
如果父进程不可遍历,那么它将向上移动父树,直到找到可遍历目录,或者触及文件系统的根目录。
dir - 指向的当前目录
getCurrentDirectory()
public void changeToParentDirectory()
getCurrentDirectory()
public void rescanCurrentDirectory()
public void ensureFileIsVisible(File f)
f - 一个File对象
public int showOpenDialog(Component parent) throws HeadlessException
parent - 对话框的父组件,可以是null ;
详见showDialog
HeadlessException - 如果GraphicsEnvironment.isHeadless()返回true。
GraphicsEnvironment.isHeadless() ,
showDialog(java.awt.Component, java.lang.String)
public int showSaveDialog(Component parent) throws HeadlessException
parent - 对话框的父组件,可以是null ;
详见showDialog
HeadlessException - 如果GraphicsEnvironment.isHeadless()返回真。
GraphicsEnvironment.isHeadless() ,
showDialog(java.awt.Component, java.lang.String)
public int showDialog(Component parent, String approveButtonText) throws HeadlessException
filechooser.showDialog(parentFrame, "Run Application");
或者,以下代码也是一样的:
JFileChooser chooser = new JFileChooser(null);
chooser.setApproveButtonText("Run Application");
chooser.showDialog(parentFrame, null);
parent参数确定了两件事情:打开的对话框所依赖的框架和放置对话框时外观和感觉应该考虑的位置的组件。 如果父对象是Frame对象(例如JFrame ),那么该对话框取决于对话框相对于框架(例如,居中在框架上)的框架和外观。 如果父类是组件,则对话框依赖于包含组件的框架,并且相对于组件定位(例如,以组件为中心)。 如果父母是null ,则对话框不依赖于可视窗口,并且它被放置在与外观相关的位置,例如屏幕的中心。
parent - 对话框的父组件;
可以null
approveButtonText - 文字
ApproveButton
HeadlessException - 如果GraphicsEnvironment.isHeadless()返回true。
GraphicsEnvironment.isHeadless()
protected JDialog createDialog(Component parent) throws HeadlessException
JDialog封装this集中在parent的框架上的parent 。
该方法可以覆盖以进一步操纵对话框,禁止调整大小,设置位置等。示例:
class MyFileChooser extends JFileChooser {
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog dialog = super.createDialog(parent);
dialog.setLocation(300, 200);
dialog.setResizable(false);
return dialog;
}
}
parent - 对话框的父组件;
可以是null
JDialog包含这个实例
HeadlessException - 如果GraphicsEnvironment.isHeadless()返回true。
GraphicsEnvironment.isHeadless()
public boolean getControlButtonsAreShown()
controlButtonsAreShown属性的值。
controlButtonsAreShown属性
setControlButtonsAreShown(boolean)
public void setControlButtonsAreShown(boolean b)
true 。
看起来,感觉总是显示这些按钮将忽略此属性的值。
此方法使用字符串值CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY作为属性的名称触发属性更改事件。
b - false如果不显示控制按钮;
否则, true
getControlButtonsAreShown() ,
CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
public int getDialogType()
JFileChooser.OPEN_DIALOG 。
setDialogType(int)
public void setDialogType(int dialogType)
OPEN_DIALOG 。
同样,使用SAVE_DIALOG让用户选择要保存的文件。
当您要在“打开”或“保存”之外的上下文中使用文件选择器时,请使用CUSTOM_DIALOG 。
例如,您可能想要启动一个允许用户选择要执行的文件的文件选择器。
请注意,您通常不需要将JFileChooser设置为使用CUSTOM_DIALOG因为调用setApproveButtonText可以为您提供此功能。
默认对话框类型为JFileChooser.OPEN_DIALOG 。
dialogType - 要显示的对话框的类型:
IllegalArgumentException - 如果
dialogType不合法
getDialogType() ,
setApproveButtonText(java.lang.String)
public void setDialogTitle(String dialogTitle)
JFileChooser窗口标题栏中的字符串。
dialogTitle - 标题栏的新
String
getDialogTitle()
public String getDialogTitle()
JFileChooser的标题
JFileChooser的字符串。
public void setApproveButtonToolTipText(String toolTipText)
ApproveButton使用的工具提示文本。
如果null ,UI对象将确定按钮的文本。
toolTipText - 批准按钮的工具提示文字
setApproveButtonText(java.lang.String) ,
setDialogType(int) ,
showDialog(java.awt.Component, java.lang.String)
public String getApproveButtonToolTipText()
ApproveButton使用的工具提示文本。
如果null ,UI对象将确定按钮的文本。
setApproveButtonText(java.lang.String) ,
setDialogType(int) ,
showDialog(java.awt.Component, java.lang.String)
public int getApproveButtonMnemonic()
setApproveButtonMnemonic(int)
public void setApproveButtonMnemonic(int mnemonic)
mnemonic - 助记键的整数值
getApproveButtonMnemonic()
public void setApproveButtonMnemonic(char mnemonic)
mnemonic - 助记键的字符值
getApproveButtonMnemonic()
public void setApproveButtonText(String approveButtonText)
ApproveButton在
FileChooserUI 。
approveButtonText -
approveButtonText使用的
ApproveButton
getApproveButtonText() ,
setDialogType(int) ,
showDialog(java.awt.Component, java.lang.String)
public String getApproveButtonText()
ApproveButton在FileChooserUI 。
如果null ,UI对象将确定按钮的文本。
通常,这将是“打开”或“保存”。
ApproveButton
setApproveButtonText(java.lang.String) ,
setDialogType(int) ,
showDialog(java.awt.Component, java.lang.String)
public FileFilter[] getChoosableFileFilters()
FileFilter所有可选择的文件过滤器的
FileFilter数组
addChoosableFileFilter(javax.swing.filechooser.FileFilter) ,
removeChoosableFileFilter(javax.swing.filechooser.FileFilter) ,
resetChoosableFileFilters()
public void addChoosableFileFilter(FileFilter filter)
setFileSelectionMode 。
filter -在
FileFilter添加到可选择文件过滤列表
getChoosableFileFilters() ,
removeChoosableFileFilter(javax.swing.filechooser.FileFilter) ,
resetChoosableFileFilters() ,
setFileSelectionMode(int)
public boolean removeChoosableFileFilter(FileFilter f)
public void resetChoosableFileFilters()
AcceptAll文件过滤器。
public FileFilter getAcceptAllFileFilter()
AcceptAll文件过滤器。
例如,在Microsoft Windows上,这将是所有文件(*。*)。
public boolean isAcceptAllFileFilterUsed()
AcceptAll FileFilter 。
AcceptAll FileFilter ,则为true
setAcceptAllFileFilterUsed(boolean)
public void setAcceptAllFileFilterUsed(boolean b)
AcceptAll FileFilter用作可选择过滤器列表中一个可用选项。
如果为false, AcceptAll文件过滤器列表中删除AcceptAll文件过滤器。
如果为true, AcceptAll文件过滤器将成为主动使用的文件过滤器。
isAcceptAllFileFilterUsed() ,
getAcceptAllFileFilter() ,
setFileFilter(javax.swing.filechooser.FileFilter)
public JComponent getAccessory()
setAccessory(javax.swing.JComponent)
public void setAccessory(JComponent newAccessory)
注意:如果有以前的附件,您应该取消注册附件可能已注册到文件选择器的任何监听器。
public void setFileSelectionMode(int mode)
JFileChooser以允许用户选择文件,只需选择目录,或选择文件和目录。
默认值为JFilesChooser.FILES_ONLY 。
mode - 要显示的文件类型:
IllegalArgumentException - 如果
mode是非法文件选择模式
getFileSelectionMode()
public int getFileSelectionMode()
JFilesChooser.FILES_ONLY 。
setFileSelectionMode(int)
public boolean isFileSelectionEnabled()
public boolean isDirectorySelectionEnabled()
public void setMultiSelectionEnabled(boolean b)
b - 如果可以选择多个文件,则为true
isMultiSelectionEnabled()
public boolean isMultiSelectionEnabled()
setMultiSelectionEnabled(boolean)
public boolean isFileHidingEnabled()
setFileHidingEnabled(boolean)
public void setFileHidingEnabled(boolean b)
FileView完成的。
b - 确定文件隐藏打开的布尔值
isFileHidingEnabled()
public void setFileFilter(FileFilter filter)
filter - 要使用的新的当前文件过滤器
getFileFilter()
public FileFilter getFileFilter()
public void setFileView(FileView fileView)
getFileView()
public FileView getFileView()
public String getName(File f)
f -
File
String包含的文件名
f
FileView.getName(java.io.File)
public String getDescription(File f)
f -
File
String f的文件
f
FileView.getDescription(java.io.File)
public String getTypeDescription(File f)
f -
File
String f的文件类型
f
FileView.getTypeDescription(java.io.File)
public Icon getIcon(File f)
f -
File
Icon或文件类型
FileView.getIcon(java.io.File)
public boolean isTraversable(File f)
f -
File
FileView.isTraversable(java.io.File)
public boolean accept(File f)
f -
File
FileFilter.accept(java.io.File)
public void setFileSystemView(FileSystemView fsv)
JFileChooser用于访问和创建文件系统资源的文件系统视图,例如查找软盘驱动器并获取根驱动器列表。
fsv - 全新
FileSystemView
FileSystemView
public FileSystemView getFileSystemView()
FileSystemView对象
setFileSystemView(javax.swing.filechooser.FileSystemView)
public void approveSelection()
APPROVE_SELECTION 。
APPROVE_SELECTION
public void cancelSelection()
CANCEL_SELECTION 。
CANCEL_SELECTION
public void addActionListener(ActionListener l)
ActionListener到文件选择器。
l - 要添加的侦听器
approveSelection() ,
cancelSelection()
public void removeActionListener(ActionListener l)
ActionListener 。
l - 要删除的侦听器
addActionListener(java.awt.event.ActionListener)
public ActionListener[] getActionListeners()
ActionListener s或一个空数组,如果没有动作侦听器当前注册
addActionListener(java.awt.event.ActionListener) ,
removeActionListener(java.awt.event.ActionListener)
protected void fireActionPerformed(String command)
command参数懒惰创建。
EventListenerList
public void updateUI()
updateUI在
JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID在
JComponent
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
public FileChooserUI getUI()
protected String paramString()
JFileChooser的字符串表示JFileChooser 。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null 。
paramString在
JComponent
JFileChooser的字符串表示
JFileChooser
public AccessibleContext getAccessibleContext()
getAccessibleContext在界面
Accessible
getAccessibleContext在
Component
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.