📄 filechooser.html
字号:
<li><a href="#navigation">Navigating the File Chooser's List</a><li><a href="#customization">Customizing the File Chooser</a></ul><p><table border=1><caption><a name="show">Creating and Showing the File Chooser</a></caption><tr><th align=left>Method or Constructor</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#JFileChooser()">JFileChooser()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#JFileChooser(java.io.File)">JFileChooser(File)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#JFileChooser(java.lang.String)">JFileChooser(String)</a> </td> <td>Create a file chooser instance. The <code>File</code> and <code>String</code> arguments, when present, provide the initial directory. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#showOpenDialog(java.awt.Component)">int showOpenDialog(Component)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#showSaveDialog(java.awt.Component)">int showSaveDialog(Component)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#showDialog(java.awt.Component, java.lang.String)">int showDialog(Component, String)</a> </td> <td>Show a modal dialog containing the file chooser. These methods return <code>APPROVE_OPTION</code> if the user approved the operation and <code>CANCEL_OPTION</code> if the user cancelled it. Another possible return value is <code>ERROR_OPTION</code>, which means an unanticipated error occurred. </td> </tr></table><p><table border=1><caption><a name="selection">Selecting Files and Directories</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setSelectedFile(java.io.File)">void setSelectedFile(File)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getSelectedFile()">File getSelectedFile()</a> </td> <td>Set or get the currently selected file or (if directory selection has been enabled) directory. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setSelectedFiles(java.io.File[])">void setSelectedFiles(File[])</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getSelectedFiles()">File[] getSelectedFiles()</a> </td> <td>Set or get the currently selected files. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setFileSelectionMode(int)">void setFileSelectionMode(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getFileSelectionMode()">void getFileSelectionMode()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#isDirectorySelectionEnabled()">boolean isDirectorySelectionEnabled()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#isFileSelectionEnabled()">boolean isFileSelectionEnabled()</a> </td> <td>Set the file selection mode. Acceptable values are <code>FILES_ONLY</code> (the default), <code>DIRECTORIES_ONLY</code>, and <code>FILES_AND_DIRECTORIES</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setMultiSelectionEnabled(boolean)">void setMultiSelectionEnabled(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#isMultiSelectionEnabled()">void isMultiSelectionEnabled()</a> </td> <td>Set or get whether multiple files can be selected at once. By default, a user can choose only one file. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setAcceptAllFileFilterUsed(boolean)">void setAcceptAllFileFilterUsed(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#isAcceptAllFileFilterUsed()">boolean isAcceptAllFileFilterUsed()</a> </td> <td>Set or get whether the <code>AcceptAll</code> file filter is used as an allowable choice in the choosable filter list; the default value is <code>true</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#createDialog(java.awt.Component)">Dialog createDialog(Component)</a> </td> <td>Given a parent component, create and return a new dialog that contains this file chooser, is dependent on the parent's frame, and is centered over the parent. </td> </tr></table><p> <table border=1> <caption><a name="navigation">Navigating the File Chooser's List</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#ensureFileIsVisible(java.io.File)">void ensureFileIsVisible(File)</a> </td> <td>Scroll the file chooser's list such that the indicated file is visible. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setCurrentDirectory(java.io.File)">void setCurrentDirectory(File)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getCurrentDirectory()">File getCurrentDirectory()</a> </td> <td>Set or get the directory whose files are displayed in the file chooser's list. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#changeToParentDirectory()">void changeToParentDirectory()</a> </td> <td>Change the list to display the current directory's parent. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#rescanCurrentDirectory()">void rescanCurrentDirectory()</a> </td> <td>Check the file system and update the chooser's list. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setDragEnabled(boolean)">void setDragEnabled(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getDragEnabled()">boolean getDragEnabled()</a> </td> <td>Set or get the property that determines whether automatic drag handling is enabled. See<a class="TutorialLink" target="_top" href="../../dnd/index.html">Drag and Drop</a> for more details. </td> </tr></table><p><table border=1><caption><a name="customization">Customizing the File Chooser</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setAccessory(javax.swing.JComponent)">void setAccessory(javax.swing.JComponent)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getAccessory()">JComponent getAccessory()</a> </td> <td>Set or get the file chooser's accessory component. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setFileFilter(javax.swing.filechooser.FileFilter)">void setFileFilter(FileFilter)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getFileFilter()">FileFilter getFileFilter()</a> </td> <td>Set or get the file chooser's primary file filter. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setFileView(javax.swing.filechooser.FileView)">void setFileView(FileView)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getFileView()">FileView getFileView()</a> </td> <td>Set or get the chooser's file view. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getChoosableFileFilters()">FileFilter[] getChoosableFileFilters()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#addChoosableFileFilter(javax.swing.filechooser.FileFilter)">void addChoosableFileFilter(FileFilter)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#removeChoosableFileFilter(javax.swing.filechooser.FileFilter)">boolean removeChoosableFileFilter(FileFilter)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#resetChoosableFileFilters()">void resetChoosableFileFilters()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getAcceptAllFileFilter()">FileFilter getAcceptAllFileFilter()</a> </td> <td>Set, get, or modify the list of user-choosable file filters. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setFileHidingEnabled(boolean)">void setFileHidingEnabled(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#isFileHidingEnabled()">boolean isFileHidingEnabled()</a> </td> <td>Set or get whether hidden files are displayed. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#setControlButtonsAreShown(boolean)">void setControlButtonsAreShown(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html#getControlButtonsAreShown()">boolean getControlButtonsAreShown()</a> </td> <td>Set or get the property that indicates whether the Approve and Cancel buttons are shown in the file chooser. This property is true by default. </td> </tr></table></blockquote><h3><a name="eg">Examples that Use File Choosers</a></h3><blockquote>This table shows the examples that use <code>JFileChooser</code>and where those examples are described.<p> <table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr><td> <a href="examples/index.html#FileChooserDemo"><code>FileChooserDemo</code></a></td><td> This section</td><td> Displays an open dialog and a save dialog.</td></tr><tr><td> <a href="examples/index.html#FileChooserDemo2"><code>FileChooserDemo2</code></a></td><td> This section</td><td> Uses a file chooser with custom filtering, a custom file view, and an accessory component.</td></tr><tr><td> <a class="TutorialLink" target="_top" href="../dnd/examples/index.html#DragFileDemo"><code>DragFileDemo</code></a></td><td> <a class="TutorialLink" target="_top" href="../dnd/intro.html">Introduction to Drag and Drop and Data Transfer</a></td><td> Uses a file chooser directly, without a dialog, and demonstrates dragging files.</td></tr><tr><td> <a href="examples/index.html#JWSFileChooserDemo"><code>JWSFileChooserDemo</code></a></td><td> This section</td><td> Uses the JNLP API to open and save files.</td></tr></table></blockquote> </blockquote> <div class=NavBit> <a target=_top href=editorpane.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=formattedtextfield.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use Editor Panes and Text Panes <br><b>Next page:</b> How to Use Formatted Text Fields </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -