java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JFileChooser
- 所有已实现的接口:
ImageObserver,MenuContainer,Serializable,Accessible
@JavaBean (defaultProperty ="UI", description ="A component which allows for the interactive selection of a file.") public class JFileChooser extends JComponent implements Accessible
JFileChooser 为用户选择文件提供了一种简单的机制。有关使用 JFileChooser 的信息,请参阅 如何使用文件选择器,The Java Tutorial 中的一个部分。
以下代码为用户的主目录弹出一个文件选择器,它只能看到 .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());
}
Warning: Swing 不是线程安全的。有关详细信息,请参阅 Swing 的线程策略。
- 自从:
- 1.2
-
内部类总结
内部类在类 javax.swing.JComponent 中声明的嵌套类/接口
JComponent.AccessibleJComponent在类 java.awt.Container 中声明的嵌套类/接口
Container.AccessibleAWTContainer -
字段摘要
字段修饰符和类型Field描述static final String标识是否使用 AcceptAllFileFilter。protected AccessibleContextAccessibleContext与此关联JFileChooserstatic final String表示正在使用不同的附件组件(例如,预览文件)。static final String标识批准(是,确定)按钮的助记符更改。static final String标识批准(是,确定)按钮上的文本更改。static final String标识批准(是,确定)按钮的工具提示文本中的更改。static final int如果选择批准(是,确定),则返回值。static final String批准当前选择的说明(与按是或确定相同)。static final int如果选择取消则返回值。static final String取消当前选择的指令。static final String标识用户可以从中选择的预定义文件过滤器列表中的更改。static final String显示控制按钮的指令。static final int表示JFileChooser支持开发人员指定的文件操作的类型值。static final String标识对话框标题的更改。static final String标识显示的文件类型的更改(仅文件、仅目录或文件和目录)。static final int仅显示目录的指令。static final String标识用户的目录更改。static final int如果发生错误则返回值。static final String用户更改了要显示的文件类型。static final String标识显示隐藏文件属性中的更改。static final String标识选择类型的变化(单个、多个等)。static final String表示正在使用不同的对象来查找系统上的可用驱动器。static final String表示正在使用不同的对象来检索文件信息。static final int显示文件和目录的指令。static final int仅显示文件的指令。static final String启用多文件选择。static final int表示JFileChooser支持“打开”文件操作的类型值。static final int表示JFileChooser支持“保存”文件操作的类型值。static final String标识用户的单个文件选择的变化。static final String识别用户多文件选择的变化。在类 javax.swing.JComponent 中声明的字段
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW在类 java.awt.Component 中声明的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT在接口 java.awt.image.ImageObserver 中声明的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
构造方法总结
构造方法构造方法描述构造一个指向用户默认目录的JFileChooser。JFileChooser(File currentDirectory) 使用给定的File作为路径构造一个JFileChooser。JFileChooser(File currentDirectory, FileSystemView fsv) 使用给定的当前目录和FileSystemView构造一个JFileChooser。JFileChooser(String currentDirectoryPath) 使用给定的路径构造一个JFileChooser。JFileChooser(String currentDirectoryPath, FileSystemView fsv) 使用给定的当前目录路径和FileSystemView构造一个JFileChooser。使用给定的FileSystemView构造一个JFileChooser。 -
方法总结
修饰符和类型方法描述boolean如果应显示文件,则返回 true。void将ActionListener添加到文件选择器。voidaddChoosableFileFilter(FileFilter filter) 将过滤器添加到用户可选择的文件过滤器列表中。void当用户点击批准按钮(默认标记为“打开”或“保存”)时由 UI 调用。void当用户选择“取消”按钮时由 UI 调用。void将目录更改为当前目录的父目录。protected JDialogcreateDialog(Component parent) 创建并返回一个新的JDialog包装this以parent为中心在parent的框架中。void确保指定的文件是可见的,而不是隐藏的。protected voidfireActionPerformed(String command) 通知所有已注册对此事件类型的通知感兴趣的监听。返回AcceptAll文件过滤器。获取与此 JFileChooser 关联的 AccessibleContext。返回附件组件。返回在此文件选择器上注册的所有动作监听的数组。int返回批准按钮的助记符。返回FileChooserUI中ApproveButton中使用的文本。返回ApproveButton中使用的工具提示文本。获取用户可选择的文件过滤器列表。boolean返回controlButtonsAreShown属性的值。返回当前目录。返回文件描述。获取JFileChooser的标题栏中的字符串。int返回此对话框的类型。boolean获取dragEnabled属性的值。返回当前选择的文件过滤器。int返回当前的文件选择模式。返回文件系统视图。返回当前文件视图。返回此文件或文件类型的图标,具体取决于系统。返回文件名。返回选定的文件。File[]如果文件选择器设置为允许多项选择,则返回所选文件的列表。返回文件类型。getUI()获取实现此组件的 L&F 的 UI 对象。返回一个字符串,该字符串指定呈现此组件的 L&F 类的名称。boolean返回是否使用AcceptAll FileFilter。boolean根据当前文件选择模式确定目录是否可选择的便捷调用。boolean如果文件选择器中没有显示隐藏文件,则返回真;否则,返回假。boolean根据当前文件选择模式确定文件是否可选择的便捷调用。boolean如果可以选择多个文件,则返回 true。boolean如果可以访问文件(目录),则返回 true。protected String返回此JFileChooser的字符串表示形式void从文件选择器中删除ActionListener。boolean从用户可选择的文件过滤器列表中删除过滤器。void告诉 UI 从当前目录重新扫描其文件列表。void将可选文件过滤器列表重置为其起始状态。voidsetAcceptAllFileFilterUsed(boolean b) 确定AcceptAll FileFilter是否用作可选过滤器列表中的可用选项。voidsetAccessory(JComponent newAccessory) 设置附件组件。voidsetApproveButtonMnemonic(char mnemonic) 使用字符设置批准按钮的助记符。voidsetApproveButtonMnemonic(int mnemonic) 使用数字键码设置批准按钮的助记符。voidsetApproveButtonText(String approveButtonText) 在FileChooserUI中设置ApproveButton中使用的文本。voidsetApproveButtonToolTipText(String toolTipText) 设置ApproveButton中使用的工具提示文本。voidsetControlButtonsAreShown(boolean b) 设置指示是否批准和cancel按钮显示在文件选择器中。voidsetCurrentDirectory(File dir) 设置当前目录。voidsetDialogTitle(String dialogTitle) 设置JFileChooser窗口标题栏中的字符串。voidsetDialogType(int dialogType) 设置此对话框的类型。voidsetDragEnabled(boolean b) 设置dragEnabled属性,该属性必须为true才能在此组件上启用自动拖动处理(拖放的第一部分)。voidsetFileFilter(FileFilter filter) 设置当前文件过滤器。voidsetFileHidingEnabled(boolean b) 设置文件隐藏打开或关闭。voidsetFileSelectionMode(int mode) 设置JFileChooser以允许用户仅选择文件、仅选择目录或同时选择文件和目录。void设置JFileChooser用于访问和创建文件系统资源的文件系统视图,例如查找软盘驱动器和获取根驱动器列表。voidsetFileView(FileView fileView) 设置用于检索 UI 信息的文件视图,例如代表文件的图标或文件的类型描述。voidsetMultiSelectionEnabled(boolean b) 设置文件选择器以允许选择多个文件。voidsetSelectedFile(File file) 设置选择的文件。voidsetSelectedFiles(File[] selectedFiles) 如果文件选择器设置为允许多项选择,则设置所选文件的列表。protected voidsetup(FileSystemView view) 执行公共构造方法初始化和设置。intshowDialog(Component parent, String approveButtonText) 弹出带有自定义批准按钮的自定义文件选择器对话框。intshowOpenDialog(Component parent) 弹出“打开文件”文件选择器对话框。intshowSaveDialog(Component parent) 弹出“保存文件”文件选择器对话框。voidupdateUI()将 UI 属性重置为当前外观的值。在类 javax.swing.JComponent 中声明的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, update在类 java.awt.Container 中声明的方法
add, 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, validateTree在类 java.awt.Component 中声明的方法
action, 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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
字段详细信息
-
OPEN_DIALOG
public static final int OPEN_DIALOG表示JFileChooser支持“打开”文件操作的类型值。- 参见:
-
SAVE_DIALOG
public static final int SAVE_DIALOG表示JFileChooser支持“保存”文件操作的类型值。- 参见:
-
CUSTOM_DIALOG
public static final int CUSTOM_DIALOG表示JFileChooser支持开发人员指定的文件操作的类型值。- 参见:
-
CANCEL_OPTION
public static final int CANCEL_OPTION如果选择取消则返回值。- 参见:
-
APPROVE_OPTION
public static final int APPROVE_OPTION如果选择批准(是,确定),则返回值。- 参见:
-
ERROR_OPTION
public static final int ERROR_OPTION如果发生错误则返回值。- 参见:
-
FILES_ONLY
public static final int FILES_ONLY仅显示文件的指令。- 参见:
-
DIRECTORIES_ONLY
public static final int DIRECTORIES_ONLY仅显示目录的指令。- 参见:
-
FILES_AND_DIRECTORIES
public static final int FILES_AND_DIRECTORIES显示文件和目录的指令。- 参见:
-
CANCEL_SELECTION
取消当前选择的指令。- 参见:
-
APPROVE_SELECTION
批准当前选择的说明(与按是或确定相同)。- 参见:
-
APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
标识批准(是,确定)按钮上的文本更改。- 参见:
-
APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
标识批准(是,确定)按钮的工具提示文本中的更改。- 参见:
-
APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
标识批准(是,确定)按钮的助记符更改。- 参见:
-
CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
显示控制按钮的指令。- 参见:
-
DIRECTORY_CHANGED_PROPERTY
标识用户的目录更改。- 参见:
-
SELECTED_FILE_CHANGED_PROPERTY
标识用户的单个文件选择的变化。- 参见:
-
SELECTED_FILES_CHANGED_PROPERTY
识别用户多文件选择的变化。- 参见:
-
MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
启用多文件选择。- 参见:
-
FILE_SYSTEM_VIEW_CHANGED_PROPERTY
表示正在使用不同的对象来查找系统上的可用驱动器。- 参见:
-
FILE_VIEW_CHANGED_PROPERTY
表示正在使用不同的对象来检索文件信息。- 参见:
-
FILE_HIDING_CHANGED_PROPERTY
标识显示隐藏文件属性中的更改。- 参见:
-
FILE_FILTER_CHANGED_PROPERTY
用户更改了要显示的文件类型。- 参见:
-
FILE_SELECTION_MODE_CHANGED_PROPERTY
标识选择类型的变化(单个、多个等)。- 参见:
-
ACCESSORY_CHANGED_PROPERTY
表示正在使用不同的附件组件(例如,预览文件)。- 参见:
-
ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
标识是否使用 AcceptAllFileFilter。- 参见:
-
DIALOG_TITLE_CHANGED_PROPERTY
标识对话框标题的更改。- 参见:
-
DIALOG_TYPE_CHANGED_PROPERTY
标识显示的文件类型的更改(仅文件、仅目录或文件和目录)。- 参见:
-
CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
标识用户可以从中选择的预定义文件过滤器列表中的更改。- 参见:
-
accessibleContext
AccessibleContext与此关联JFileChooser
-
-
构造方法详细信息
-
JFileChooser
public JFileChooser()构造一个指向用户默认目录的JFileChooser。此默认值取决于操作系统。它在 Windows 上通常是“Documents”文件夹,在 Unix 上通常是用户的主目录。 -
JFileChooser
使用给定的路径构造一个JFileChooser。传入null字符串会使文件选择器指向用户的默认目录。此默认值取决于操作系统。它在 Windows 上通常是“Documents”文件夹,在 Unix 上通常是用户的主目录。- 参数:
currentDirectoryPath- 一个String给出文件或目录的路径
-
JFileChooser
使用给定的File作为路径构造一个JFileChooser。传入null文件会使文件选择器指向用户的默认目录。此默认值取决于操作系统。它在 Windows 上通常是“Documents”文件夹,在 Unix 上通常是用户的主目录。- 参数:
currentDirectory- 一个File对象指定文件或目录的路径
-
JFileChooser
使用给定的FileSystemView构造一个JFileChooser。- 参数:
fsv- 一个FileSystemView
-
JFileChooser
使用给定的当前目录和FileSystemView构造一个JFileChooser。- 参数:
currentDirectory- 一个File对象指定文件或目录的路径fsv- 一个FileSystemView
-
JFileChooser
使用给定的当前目录路径和FileSystemView构造一个JFileChooser。- 参数:
currentDirectoryPath- 一个String指定文件或目录的路径fsv- 一个FileSystemView
-
-
方法详情
-
setup
执行公共构造方法初始化和设置。- 参数:
view- 用于设置的FileSystemView
-
setDragEnabled
@BeanProperty (bound =false, description ="determines whether automatic drag handling is enabled") public void setDragEnabled(boolean b) 设置dragEnabled属性,该属性必须为true才能在此组件上启用自动拖动处理(拖放的第一部分)。transferHandler属性需要设置为非null值才能让拖动执行任何操作。dragEnabled属性的默认值为false。启用自动拖动处理后,只要用户在项目上按下鼠标按钮然后将鼠标移动几个像素,大多数外观就会开始拖放操作。因此,将此属性设置为
true会对选择的行为方式产生微妙的影响。有些外观可能不支持自动拖放;他们将忽略此属性。您可以通过修改组件以直接调用
TransferHandler的exportAsDrag方法来解决此类外观问题。- 参数:
b- 将dragEnabled属性设置为的值- 抛出:
HeadlessException- 如果b是true并且GraphicsEnvironment.isHeadless()返回true- 自从:
- 1.4
- 参见:
-
getDragEnabled
public boolean getDragEnabled()获取dragEnabled属性的值。- 返回:
dragEnabled属性的值- 自从:
- 1.4
- 参见:
-
getSelectedFile
返回选定的文件。这可以由程序员通过setSelectedFile或通过用户操作来设置,例如将文件名键入 UI 或从 UI 的列表中选择文件。- 返回:
- 所选文件
- 参见:
-
setSelectedFile
设置选择的文件。如果文件的父目录不是当前目录,则将当前目录更改为文件的父目录。- 参数:
file- 选定的文件- 参见:
-
getSelectedFiles
如果文件选择器设置为允许多项选择,则返回所选文件的列表。- 返回:
-
选定的
File数组
-
setSelectedFiles
@BeanProperty (description ="The list of selected files if the chooser is in multiple selection mode.") public void setSelectedFiles(File [] selectedFiles) 如果文件选择器设置为允许多项选择,则设置所选文件的列表。- 参数:
selectedFiles- 要选择的数组Files
-
getCurrentDirectory
返回当前目录。- 返回:
- 当前目录
- 参见:
-
setCurrentDirectory
@BeanProperty (preferred =true, description ="The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir) 设置当前目录。传入null会将文件选择器设置为指向用户的默认目录。此默认值取决于操作系统。它在 Windows 上通常是“Documents”文件夹,在 Unix 上通常是用户的主目录。如果作为currentDirectory传入的文件不是目录,则文件的父级将用作 currentDirectory。如果父节点不可遍历,那么它将沿着父树向上遍历,直到找到一个可遍历的目录,或者到达文件系统的根目录。- 参数:
dir- 要指向的当前目录- 参见:
-
changeToParentDirectory
public void changeToParentDirectory()将目录更改为当前目录的父目录。- 参见:
-
rescanCurrentDirectory
public void rescanCurrentDirectory()告诉 UI 从当前目录重新扫描其文件列表。 -
ensureFileIsVisible
确保指定的文件是可见的,而不是隐藏的。- 参数:
f- 文件对象
-
showOpenDialog
弹出“打开文件”文件选择器对话框。请注意,批准按钮中显示的文本由 L&F 确定。- 参数:
parent- 对话框的父组件,可以是null;详情见showDialog- 返回:
-
弹出文件选择器的返回状态:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION 如果发生错误或对话框被关闭
- 抛出:
HeadlessException- 如果 GraphicsEnvironment.isHeadless() 返回 true。- 参见:
-
showSaveDialog
弹出“保存文件”文件选择器对话框。请注意,批准按钮中显示的文本由 L&F 确定。- 参数:
parent- 对话框的父组件,可以是null;详情见showDialog- 返回:
-
弹出文件选择器的返回状态:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION 如果发生错误或对话框被关闭
- 抛出:
HeadlessException- 如果 GraphicsEnvironment.isHeadless() 返回 true。- 参见:
-
showDialog
弹出带有自定义批准按钮的自定义文件选择器对话框。例如,以下代码弹出一个带有“运行应用程序”按钮(而不是正常的“保存”或“打开”按钮)的文件选择器:filechooser.showDialog(parentFrame, "Run Application");
或者,以下代码做同样的事情:JFileChooser chooser = new JFileChooser(null); chooser.setApproveButtonText("Run Application"); chooser.showDialog(parentFrame, null);parent参数决定了两件事:打开的对话框所依赖的框架和放置对话框时外观应该考虑其位置的组件。如果父级是Frame对象(例如JFrame),则对话框取决于框架,并且外观和感觉会相对于框架定位对话框(例如,在框架上居中)。如果父级是组件,则对话框取决于包含组件的框架,并且相对于组件定位(例如,在组件上方居中)。如果父级是null,则对话框不依赖于任何可见窗口,并且它被放置在依赖于外观和感觉的位置,例如屏幕中心。- 参数:
parent- 对话框的父组件;可以是nullapproveButtonText-ApproveButton的文本- 返回:
-
弹出文件选择器的返回状态:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION 如果发生错误或对话框被关闭
- 抛出:
HeadlessException- 如果 GraphicsEnvironment.isHeadless() 返回 true。- 参见:
-
createDialog
创建并返回一个新的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。- 自从:
- 1.4
- 参见:
-
getControlButtonsAreShown
public boolean getControlButtonsAreShown()返回controlButtonsAreShown属性的值。- 返回:
controlButtonsAreShown属性的值- 自从:
- 1.3
- 参见:
-
setControlButtonsAreShown
@BeanProperty (preferred =true, description ="Sets whether the approve & cancel buttons are shown.") public void setControlButtonsAreShown(boolean b) 设置指示是否批准和cancel按钮显示在文件选择器中。此属性默认为true。看起来总是显示这些按钮会忽略此属性的值。此方法使用CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY的字符串值作为属性名称来触发属性更改事件。- 参数:
b-false如果不应显示控制按钮;否则,true- 自从:
- 1.3
- 参见:
-
getDialogType
public int getDialogType()返回此对话框的类型。默认值为JFileChooser.OPEN_DIALOG。- 返回:
-
要显示的对话框类型:
- JFileChooser.OPEN_DIALOG
- JFileChooser.SAVE_DIALOG
- JFileChooser.CUSTOM_DIALOG
- 参见:
-
setDialogType
@BeanProperty (preferred =true, enumerationValues ={"JFileChooser.OPEN_DIALOG","JFileChooser.SAVE_DIALOG","JFileChooser.CUSTOM_DIALOG"}, description ="The type (open, save, custom) of the JFileChooser.") public void setDialogType(int dialogType) 设置此对话框的类型。当您想要调出用户可以用来打开文件的文件选择器时,请使用OPEN_DIALOG。同样,使用SAVE_DIALOG让用户选择要保存的文件。当您想在“打开”或“保存”以外的上下文中使用文件选择器时,请使用CUSTOM_DIALOG。例如,您可能想要调出一个文件选择器,允许用户选择要执行的文件。请注意,您通常不需要将JFileChooser设置为使用CUSTOM_DIALOG,因为调用setApproveButtonText会为您完成此操作。默认对话框类型是JFileChooser.OPEN_DIALOG。- 参数:
dialogType- 要显示的对话框类型:- JFileChooser.OPEN_DIALOG
- JFileChooser.SAVE_DIALOG
- JFileChooser.CUSTOM_DIALOG
- 抛出:
IllegalArgumentException- 如果dialogType不合法- 参见:
-
setDialogTitle
@BeanProperty (preferred =true, description ="The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle) 设置JFileChooser窗口标题栏中的字符串。- 参数:
dialogTitle- 标题栏的新String- 参见:
-
getDialogTitle
获取JFileChooser的标题栏中的字符串。- 返回:
JFileChooser窗口标题栏中的字符串- 参见:
-
setApproveButtonToolTipText
@BeanProperty (preferred =true, description ="The tooltip text for the ApproveButton.") public void setApproveButtonToolTipText(String toolTipText) 设置ApproveButton中使用的工具提示文本。如果为null,则 UI 对象将确定按钮的文本。- 参数:
toolTipText- 批准按钮的工具提示文本- 参见:
-
getApproveButtonToolTipText
返回ApproveButton中使用的工具提示文本。如果为null,则 UI 对象将确定按钮的文本。- 返回:
- 用于批准按钮的工具提示文本
- 参见:
-
getApproveButtonMnemonic
public int getApproveButtonMnemonic()返回批准按钮的助记符。- 返回:
- 助记键的整数值
- 参见:
-
setApproveButtonMnemonic
@BeanProperty (preferred =true, description ="The mnemonic key accelerator for the ApproveButton.") public void setApproveButtonMnemonic(int mnemonic) 使用数字键码设置批准按钮的助记符。- 参数:
mnemonic- 助记键的整数值- 参见:
-
setApproveButtonMnemonic
public void setApproveButtonMnemonic(char mnemonic) 使用字符设置批准按钮的助记符。- 参数:
mnemonic- 助记键的字符值- 参见:
-
setApproveButtonText
@BeanProperty (preferred =true, description ="The text that goes in the ApproveButton.") public void setApproveButtonText(String approveButtonText) 在FileChooserUI中设置ApproveButton中使用的文本。- 参数:
approveButtonText-ApproveButton中使用的文本- 参见:
-
getApproveButtonText
返回FileChooserUI中ApproveButton中使用的文本。如果为null,则 UI 对象将确定按钮的文本。通常,这将是“打开”或“保存”。- 返回:
ApproveButton中使用的文本- 参见:
-
getChoosableFileFilters
获取用户可选择的文件过滤器列表。- 返回:
-
包含所有可选文件过滤器的
FileFilter数组 - 参见:
-
addChoosableFileFilter
@BeanProperty (preferred =true, description ="Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter) 将过滤器添加到用户可选择的文件过滤器列表中。有关设置文件选择模式的信息,请参阅setFileSelectionMode。- 参数:
filter- 添加到可选文件过滤器列表的FileFilter- 参见:
-
removeChoosableFileFilter
从用户可选择的文件过滤器列表中删除过滤器。如果删除了文件过滤器,则返回 true。- 参数:
f- 要删除的文件过滤器- 返回:
- 如果删除了文件过滤器,则为 true,否则为 false
- 参见:
-
resetChoosableFileFilters
public void resetChoosableFileFilters()将可选文件过滤器列表重置为其起始状态。通常,这会删除所有添加的文件过滤器,同时保留AcceptAll文件过滤器。- 参见:
-
getAcceptAllFileFilter
返回AcceptAll文件过滤器。例如,在 Microsoft Windows 上,这将是所有文件 (*.*)。- 返回:
AcceptAll文件过滤器
-
isAcceptAllFileFilterUsed
public boolean isAcceptAllFileFilterUsed()返回是否使用AcceptAll FileFilter。- 返回:
-
如果使用
AcceptAll FileFilter则为真 - 自从:
- 1.3
- 参见:
-
setAcceptAllFileFilterUsed
@BeanProperty (preferred =true, description ="Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.") public void setAcceptAllFileFilterUsed(boolean b) 确定AcceptAll FileFilter是否用作可选过滤器列表中的可用选项。如果为假,AcceptAll文件过滤器将从可用文件过滤器列表中删除。如果为真,AcceptAll文件过滤器将成为活跃使用的文件过滤器。- 参数:
b- 一个boolean确定AcceptAll文件过滤器是否是可选过滤器列表中的可用选择- 自从:
- 1.3
- 参见:
-
getAccessory
返回附件组件。- 返回:
- 此 JFileChooser 的附属组件,或 null
- 参见:
-
setAccessory
@BeanProperty (preferred =true, description ="Sets the accessory component on the JFileChooser.") public void setAccessory(JComponent newAccessory) 设置附件组件。附件通常用于显示所选文件的预览图像;但是,它可以用于程序员希望的任何用途,例如额外的自定义文件选择器控件。注意:如果有以前的附件,您应该取消注册附件可能已向文件选择器注册的任何监听。
- 参数:
newAccessory- 要设置的附件组件
-
setFileSelectionMode
@BeanProperty (preferred =true, enumerationValues ={"JFileChooser.FILES_ONLY","JFileChooser.DIRECTORIES_ONLY","JFileChooser.FILES_AND_DIRECTORIES"}, description ="Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode) 设置JFileChooser以允许用户仅选择文件、仅选择目录或同时选择文件和目录。默认值为JFilesChooser.FILES_ONLY。- 参数:
mode- 要显示的文件类型:- JFileChooser.FILES_ONLY
- JFileChooser.DIRECTORIES_ONLY
- JFileChooser.FILES_AND_DIRECTORIES
- 抛出:
IllegalArgumentException- 如果mode是非法文件选择模式- 参见:
-
getFileSelectionMode
public int getFileSelectionMode()返回当前的文件选择模式。默认值为JFilesChooser.FILES_ONLY。- 返回:
-
要显示的文件类型,以下之一:
- JFileChooser.FILES_ONLY
- JFileChooser.DIRECTORIES_ONLY
- JFileChooser.FILES_AND_DIRECTORIES
- 参见:
-
isFileSelectionEnabled
根据当前文件选择模式确定文件是否可选择的便捷调用。- 返回:
- 如果文件是可选的,则为 true,否则为 false
- 参见:
-
isDirectorySelectionEnabled
根据当前文件选择模式确定目录是否可选择的便捷调用。- 返回:
- 如果目录是可选的,则为 true,否则为 false
- 参见:
-
setMultiSelectionEnabled
@BeanProperty (description ="Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b) 设置文件选择器以允许选择多个文件。- 参数:
b- 如果可以选择多个文件则为真- 参见:
-
isMultiSelectionEnabled
public boolean isMultiSelectionEnabled()如果可以选择多个文件,则返回 true。- 返回:
- 如果可以选择多个文件则为真
- 参见:
-
isFileHidingEnabled
public boolean isFileHidingEnabled()如果文件选择器中没有显示隐藏文件,则返回真;否则,返回假。此属性的默认值可能源自底层操作系统。- 返回:
- 文件隐藏属性的状态
- 参见:
-
setFileHidingEnabled
@BeanProperty (preferred =true, description ="Sets file hiding on or off.") public void setFileHidingEnabled(boolean b) 设置文件隐藏打开或关闭。如果为真,则隐藏文件不会显示在文件选择器中。确定显示哪些文件的工作由FileView完成。- 参数:
b- 决定文件隐藏是否打开的boolean- 参见:
-
setFileFilter
@BeanProperty (preferred =true, description ="Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter) 设置当前文件过滤器。文件选择器使用文件过滤器从用户视图中过滤掉文件。- 参数:
filter- 要使用的新的当前文件过滤器- 参见:
-
getFileFilter
返回当前选择的文件过滤器。- 返回:
- 当前文件过滤器
- 参见:
-
setFileView
@BeanProperty (preferred =true, description ="Sets the File View used to get file type information.") public void setFileView(FileView fileView) 设置用于检索 UI 信息的文件视图,例如代表文件的图标或文件的类型描述。- 参数:
fileView- 用于检索 UI 信息的FileView- 参见:
-
getFileView
返回当前文件视图。- 返回:
- 当前文件视图
- 参见:
-
getName
返回文件名。- 参数:
f-File- 返回:
String包含f的文件名- 参见:
-
getDescription
返回文件描述。- 参数:
f-File- 返回:
String包含f的文件描述- 参见:
-
getTypeDescription
返回文件类型。- 参数:
f-File- 返回:
String包含f的文件类型描述- 参见:
-
getIcon
返回此文件或文件类型的图标,具体取决于系统。- 参数:
f-File- 返回:
-
此文件的
Icon或文件类型 - 参见:
-
isTraversable
如果可以访问文件(目录),则返回 true。如果无法遍历目录,则返回 false。- 参数:
f-File- 返回:
- 如果可以遍历文件/目录,则为 true,否则为 false
- 参见:
-
accept
如果应显示文件,则返回 true。- 参数:
f-File- 返回:
- 如果应显示文件,则为 true,否则为 false
- 参见:
-
setFileSystemView
@BeanProperty (expert =true, description ="Sets the FileSytemView used to get filesystem information.") public void setFileSystemView(FileSystemView fsv) 设置JFileChooser用于访问和创建文件系统资源的文件系统视图,例如查找软盘驱动器和获取根驱动器列表。- 参数:
fsv- 新的FileSystemView- 参见:
-
getFileSystemView
返回文件系统视图。- 返回:
FileSystemView对象- 参见:
-
approveSelection
public void approveSelection()当用户点击批准按钮(默认标记为“打开”或“保存”)时由 UI 调用。这也可以由程序员调用。此方法会触发一个动作事件,命令字符串等于APPROVE_SELECTION。- 参见:
-
cancelSelection
public void cancelSelection()当用户选择“取消”按钮时由 UI 调用。这也可以由程序员调用。此方法会触发一个操作事件,命令字符串等于CANCEL_SELECTION。- 参见:
-
addActionListener
将ActionListener添加到文件选择器。- 参数:
l- 要添加的监听器- 参见:
-
removeActionListener
从文件选择器中删除ActionListener。- 参数:
l- 要删除的监听器- 参见:
-
getActionListeners
返回在此文件选择器上注册的所有动作监听的数组。- 返回:
-
此文件选择器的所有
ActionListeners 或空数组(如果当前未注册任何动作监听器) - 自从:
- 1.4
- 参见:
-
fireActionPerformed
通知所有已注册对此事件类型的通知感兴趣的监听器。事件实例是使用command参数延迟创建的。- 参数:
command- 一个字符串,可以指定与事件关联的命令- 参见:
-
updateUI
public void updateUI()将 UI 属性重置为当前外观的值。- 重写:
updateUI在类JComponent中- 参见:
-
getUIClassID
@BeanProperty (bound =false, expert =true, description ="A string that specifies the name of the L&F class.") public String getUIClassID()返回一个字符串,该字符串指定呈现此组件的 L&F 类的名称。- 重写:
getUIClassID在类JComponent中- 返回:
- 字符串“FileChooserUI”
- 参见:
-
getUI
获取实现此组件的 L&F 的 UI 对象。- 重写:
getUI在类JComponent中- 返回:
- 实现 FileChooserUI L&F 的 FileChooserUI 对象
-
paramString
返回此JFileChooser的字符串表示形式。此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。返回的字符串可能为空,但可能不是null。- 重写:
paramString在类JComponent中- 返回:
-
这个
JFileChooser的字符串表示
-
getAccessibleContext
获取与此 JFileChooser 关联的 AccessibleContext。对于文件选择器,AccessibleContext 采用 AccessibleJFileChooser 的形式。如有必要,将创建一个新的 AccessibleJFileChooser 实例。- 指定者:
getAccessibleContext在接口Accessible中- 重写:
getAccessibleContext在类Component中- 返回:
- 作为此 JFileChooser 的 AccessibleContext 的 AccessibleJFileChooser
-