Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.swing
Class JFileChooser

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Container
                  |
                  +--javax.swing.JComponent
                        |
                        +--javax.swing.JFileChooser

public class JFileChooser
extends JComponent
implements Accessible

JFileChooser provides a simple mechanism for the user to chooser a file. The following pops up a file chooser in the users home directory that only sees .jpg and .gif images: JFileChooser chooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter(); filter.addExtension("jpg"); filter.addExtension("gif"); filter.setDescription("JPG & GIF Images"); 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()); }

See Also:
  Serialized Form

Inner Class Summary
`protected class` | `JFileChooser.AccessibleJFileChooser` The class used to obtain the accessible context for this object.

Inner classes inherited from class javax.swing.JComponent
`JComponent.AccessibleJComponent`

Field Summary
`protected AccessibleContext` | `accessibleContext`
`static java.lang.String` | `ACCESSORY_CHANGED_PROPERTY` Says that a different accessory component is in use.
`static java.lang.String` | `APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY` Identifies change in the mnemonic for the approve (yes, ok) button .
`static java.lang.String` | `APPROVE_BUTTON_TEXT_CHANGED_PROPERTY` Identifies change in the text on the approve (yes, ok) button.
`static java.lang.String` | `APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY` Identifies change in the tooltip text for the approve (yes, ok) button .
`static int` | `APPROVE_OPTION` Return value if approve (yes, ok) is chosen.
`static java.lang.String` | `APPROVE_SELECTION` Instruction to approve the current selection (Same as pressing yes or ok.)
`static int` | `CANCEL_OPTION` Return value if cancel is chosen.
`static java.lang.String` | `CANCEL_SELECTION` Instruction to cancel the current selection.
`static java.lang.String` | `CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY` Identifies a change in the list of predefined file filters the user can choose from
`static int` | `CUSTOM_DIALOG` Type value indicating that the FileChooser supports a developer sepcified file operation.
`static java.lang.String` | `DIALOG_TITLE_CHANGED_PROPERTY` Identifies a change in the dialog title.
`static java.lang.String` | `DIALOG_TYPE_CHANGED_PROPERTY` Identifies a change in the type of files displayed (files only, directories only, or both files and directories.
`static int` | `DIRECTORIES_ONLY` Instruction to display only directories.
`static java.lang.String` | `DIRECTORY_CHANGED_PROPERTY` Identifies user's directory change.
`static int` | `ERROR_OPTION` Return value if an error occured.
`static java.lang.String` | `FILE_FILTER_CHANGED_PROPERTY` User changed the kind of files to display.
`static java.lang.String` | `FILE_HIDING_CHANGED_PROPERTY` Identifies a change in the display-hidden-files property.
`static java.lang.String` | `FILE_SELECTION_MODE_CHANGED_PROPERTY` Identifies a change in the kind of selection (single, multiple, etc.).
`static java.lang.String` | `FILE_SYSTEM_VIEW_CHANGED_PROPERTY` Says that a different object is being used to find available drives on the system.
`static java.lang.String` | `FILE_VIEW_CHANGED_PROPERTY` Says that a different object is being used to retrieve file information.
`static int` | `FILES_AND_DIRECTORIES` Instruction to display both files and directories.
`static int` | `FILES_ONLY` Instruction to display only files.
`static java.lang.String` | `MULTI_SELECTION_ENABLED_CHANGED_PROPERTY` Enables multiple-file selections.
`static int` | `OPEN_DIALOG` Type value indicating that the FileChooser supports an "Open" file operation.
`static int` | `SAVE_DIALOG` Type value indicating that the FileChooser supports a "Save" file operation.
`static java.lang.String` | `SELECTED_FILE_CHANGED_PROPERTY` Identifes change in user's single-file selection.
`static java.lang.String` | `SELECTED_FILES_CHANGED_PROPERTY` Identifes change in user's multiple-file selection.

Fields inherited from class javax.swing.JComponent
`accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW`

Fields inherited from class java.awt.Component
`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

Constructor Summary
`JFileChooser()` Creates a JFileChooser pointing to the user's home directory.
`JFileChooser(java.io.File currentDirectory)` Creates a JFileChooser using the given File as the path.
`JFileChooser(java.io.File currentDirectory, FileSystemView fsv)` Creates a JFileChooser using the given current directory and FileSystemView
`JFileChooser(FileSystemView fsv)` Creates a JFileChooser using the given FileSystemView
`JFileChooser(java.lang.String currentDirectoryPath)` Creates a JFileChooser using the given path.
`JFileChooser(java.lang.String currentDirectoryPath, FileSystemView fsv)` Creates a JFileChooser using the given current directory path and FileSystemView

Method Summary
`boolean` | `accept(java.io.File f)` Returns true if the file should be displayed.
`void` | `addActionListener(java.awt.event.ActionListener l)` adds an ActionListener to the button
`void` | `addChoosableFileFilter(FileFilter filter)` Adds a filter to the list of user choosable file filters.
`void` | `approveSelection()` Called by the UI when the user hits the approve (AKA "Open" or "Save") button.
`void` | `cancelSelection()` Called by the UI when the user hits the cancel button.
`void` | `changeToParentDirectory()` Changes the directory to be set to the parent of the current directory.
`void` | `ensureFileIsVisible(java.io.File f)` Make sure that the specified file is viewable, and not hidden.
`protected void` | `fireActionPerformed(java.lang.String command)` Notify all listeners that have registered interest for notification on this event type.
`FileFilter` | `getAcceptAllFileFilter()` Returns the AcceptAll file filter (e.g.
`AccessibleContext` | `getAccessibleContext()` Get the AccessibleContext associated with this JFileChooser
`JComponent` | `getAccessory()` Return the accessory component.
`int` | `getApproveButtonMnemonic()` Returns the approve button's mnemonic.
`java.lang.String` | `getApproveButtonText()` Returns the text used in the ApproveButton in the FileChooserUI.
`java.lang.String` | `getApproveButtonToolTipText()` Returns the tooltip text used in the ApproveButton.
`FileFilter[]` | `getChoosableFileFilters()` Gets the list of user choosable file filters
`java.io.File` | `getCurrentDirectory()` Returns the current directory.
`java.lang.String` | `getDescription(java.io.File f)` Returns the file description.
`java.lang.String` | `getDialogTitle()` Gets the string that goes in the FileChooser's titlebar.
`int` | `getDialogType()` Returns the type of this dialog.
`FileFilter` | `getFileFilter()` Returns the currently selected file filter.
`int` | `getFileSelectionMode()` Returns the current file-selection mode.
`FileSystemView` | `getFileSystemView()` Returns the file system view.
`FileView` | `getFileView()` Returns the current file view.
`Icon` | `getIcon(java.io.File f)` Returns the icon for this file or type of file, depending on the system.
`java.lang.String` | `getName(java.io.File f)` Returns the file name.
`java.io.File` | `getSelectedFile()` Returns the selected file.
`java.io.File[]` | `getSelectedFiles()` Returns a list of selected files if the filechooser is set to allow multi-selection.
`java.lang.String` | `getTypeDescription(java.io.File f)` Returns the file type.
`FileChooserUI` | `getUI()` Gets the UI object which implements the L&F for this component.
`java.lang.String` | `getUIClassID()` Returns a string that specifies the name of the L&F class that renders this component.
`boolean` | `isDirectorySelectionEnabled()` Convenience call that determines if directories are selectable based on the current file selection mode
`boolean` | `isFileHidingEnabled()` If true, hidden files are not shown in the filechooser
`boolean` | `isFileSelectionEnabled()` Convenience call that determines if files are selectable based on the current file selection mode
`boolean` | `isMultiSelectionEnabled()` Returns true if multiple files can be selected.
`boolean` | `isTraversable(java.io.File f)` Returns true if the file (directory) can be visited.
`protected java.lang.String` | `paramString()` Returns a string representation of this JFileChooser.
`void` | `removeActionListener(java.awt.event.ActionListener l)` removes an ActionListener from the button
`boolean` | `removeChoosableFileFilter(FileFilter f)` Removes a filter from the list of user choosable file filters.
`void` | `rescanCurrentDirectory()` Tells the UI to rescan it's files list from the current directory.
`void` | `resetChoosableFileFilters()` Resets the choosable file filter list to it's starting state.
`void` | `setAccessory(JComponent newAccessory)` Sets the accessory component.
`void` | `setApproveButtonMnemonic(char mnemonic)` Sets the approve button's mnemonic using a character.
`void` | `setApproveButtonMnemonic(int mnemonic)` Sets the approve button's mnemonic using a numeric keycode.
`void` | `setApproveButtonText(java.lang.String approveButtonText)` Sets the text used in the ApproveButton in the FileChooserUI.
`void` | `setApproveButtonToolTipText(java.lang.String toolTipText)` Sets the tooltip text used in the ApproveButton.
`void` | `setCurrentDirectory(java.io.File dir)` Sets the current directory.
`void` | `setDialogTitle(java.lang.String dialogTitle)` Sets the string that goes in the FileChooser window's title bar.
`void` | `setDialogType(int dialogType)` Sets the type of this dialog.
`void` | `setFileFilter(FileFilter filter)` Sets the current File Filter.
`void` | `setFileHidingEnabled(boolean b)` Sets file hiding on or off.
`void` | `setFileSelectionMode(int mode)` Sets the FileChooser to allow the user to just select files, just select directories, or select both files and directetories.
`void` | `setFileSystemView(FileSystemView fsv)` Sets the file system view which the JFileChooser uses to access and create file system resouces, such as finding the floppy drive and getting a list of root drives.
`void` | `setFileView(FileView fileView)` Sets the file view to used to retrieve UI information, such as the icon that represents a file or the type description of a file.
`void` | `setMultiSelectionEnabled(boolean b)` Sets the filechooser to allow multiple file selections.
`void` | `setSelectedFile(java.io.File selectedFile)` Sets the selected file.
`void` | `setSelectedFiles(java.io.File[] selectedFiles)` Sets the list of selected files if the filechooser is set to allow multi-selection.
`protected void` | `setup(FileSystemView view)` Perform common constructor initialization and setup
`int` | `showDialog(java.awt.Component parent, java.lang.String approveButtonText)` Pops a custom file chooser dialog with a custom ApproveButton.
`int` | `showOpenDialog(java.awt.Component parent)` Pops up an "Open File" file chooser dialog.
`int` | `showSaveDialog(java.awt.Component parent)` Pops up a "Save File" file chooser dialog.
`void` | `updateUI()` Notification from the UIFactory that the L&F has changed.

Methods inherited from class javax.swing.JComponent
`addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update`

Methods inherited from class java.awt.Container
`add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree`

Methods inherited from class java.awt.Component
`action, add, addComponentListener, addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, getBackground, getBounds, getColorModel, getCursor, getFont, getFontMetrics, getForeground, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isEnabled, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### OPEN_DIALOG

    public static final int OPEN_DIALOG

  Type value indicating that the FileChooser supports an "Open" file operation.

### SAVE_DIALOG

    public static final int SAVE_DIALOG

  Type value indicating that the FileChooser supports a "Save" file operation.

### CUSTOM_DIALOG

    public static final int CUSTOM_DIALOG

  Type value indicating that the FileChooser supports a developer sepcified file operation.

### CANCEL_OPTION

    public static final int CANCEL_OPTION

  Return value if cancel is chosen.

### APPROVE_OPTION

    public static final int APPROVE_OPTION

  Return value if approve (yes, ok) is chosen.

### ERROR_OPTION

    public static final int ERROR_OPTION

  Return value if an error occured.

### FILES_ONLY

    public static final int FILES_ONLY

  Instruction to display only files.

### DIRECTORIES_ONLY

    public static final int DIRECTORIES_ONLY

  Instruction to display only directories.

### FILES_AND_DIRECTORIES

    public static final int FILES_AND_DIRECTORIES

  Instruction to display both files and directories.

### CANCEL_SELECTION

    public static final java.lang.String CANCEL_SELECTION

  Instruction to cancel the current selection.

### APPROVE_SELECTION

    public static final java.lang.String APPROVE_SELECTION

  Instruction to approve the current selection (Same as pressing yes or ok.)

### APPROVE_BUTTON_TEXT_CHANGED_PROPERTY

    public static final java.lang.String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY

  Identifies change in the text on the approve (yes, ok) button.

### APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY

    public static final java.lang.String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY

  Identifies change in the tooltip text for the approve (yes, ok) button .

### APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY

    public static final java.lang.String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY

  Identifies change in the mnemonic for the approve (yes, ok) button .

### DIRECTORY_CHANGED_PROPERTY

    public static final java.lang.String DIRECTORY_CHANGED_PROPERTY

  Identifies user's directory change.

### SELECTED_FILE_CHANGED_PROPERTY

    public static final java.lang.String SELECTED_FILE_CHANGED_PROPERTY

  Identifes change in user's single-file selection.

### SELECTED_FILES_CHANGED_PROPERTY

    public static final java.lang.String SELECTED_FILES_CHANGED_PROPERTY

  Identifes change in user's multiple-file selection.

### MULTI_SELECTION_ENABLED_CHANGED_PROPERTY

    public static final java.lang.String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY

  Enables multiple-file selections.

### FILE_SYSTEM_VIEW_CHANGED_PROPERTY

    public static final java.lang.String FILE_SYSTEM_VIEW_CHANGED_PROPERTY

  Says that a different object is being used to find available drives on the system.

### FILE_VIEW_CHANGED_PROPERTY

    public static final java.lang.String FILE_VIEW_CHANGED_PROPERTY

  Says that a different object is being used to retrieve file information.

### FILE_HIDING_CHANGED_PROPERTY

    public static final java.lang.String FILE_HIDING_CHANGED_PROPERTY

  Identifies a change in the display-hidden-files property.

### FILE_FILTER_CHANGED_PROPERTY

    public static final java.lang.String FILE_FILTER_CHANGED_PROPERTY

  User changed the kind of files to display.

### FILE_SELECTION_MODE_CHANGED_PROPERTY

    public static final java.lang.String FILE_SELECTION_MODE_CHANGED_PROPERTY

  Identifies a change in the kind of selection (single, multiple, etc.).

### ACCESSORY_CHANGED_PROPERTY

    public static final java.lang.String ACCESSORY_CHANGED_PROPERTY

  Says that a different accessory component is in use. (For example, to preview files.)

### DIALOG_TITLE_CHANGED_PROPERTY

    public static final java.lang.String DIALOG_TITLE_CHANGED_PROPERTY

  Identifies a change in the dialog title.

### DIALOG_TYPE_CHANGED_PROPERTY

    public static final java.lang.String DIALOG_TYPE_CHANGED_PROPERTY

  Identifies a change in the type of files displayed (files only, directories only, or both files and directories.

### CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY

    public static final java.lang.String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY

  Identifies a change in the list of predefined file filters the user can choose from

### accessibleContext

    protected AccessibleContext accessibleContext

Constructor Detail

### JFileChooser

    public JFileChooser()

  Creates a JFileChooser pointing to the user's home directory.

### JFileChooser

    public JFileChooser(java.lang.String currentDirectoryPath)

  Creates a JFileChooser using the given path. Passing in a null string causes the file chooser to point to the users home directory.
  Parameters:
    `path` - a String giving the path to a file or directory

### JFileChooser

    public JFileChooser(java.io.File currentDirectory)

  Creates a JFileChooser using the given File as the path. Passing in a null file causes the file chooser to point to the users's home directory.
  Parameters:
    `directory` - a File object specifying the path to a file or directory

### JFileChooser

    public JFileChooser(FileSystemView fsv)

  Creates a JFileChooser using the given FileSystemView

### JFileChooser

    public JFileChooser(java.io.File currentDirectory,
                        FileSystemView fsv)

  Creates a JFileChooser using the given current directory and FileSystemView

### JFileChooser

    public JFileChooser(java.lang.String currentDirectoryPath,
                        FileSystemView fsv)

  Creates a JFileChooser using the given current directory path and FileSystemView

Method Detail

### setup

    protected void setup(FileSystemView view)

  Perform common constructor initialization and setup

### getSelectedFile

    public java.io.File getSelectedFile()

  Returns the selected file. This can be set either by the programmer via setFile() or by a user action, such as either typing the filename int the UI or selecting the file from a list in the UI.
  Returns:
    the selected file
  See Also:
    `setSelectedFile(java.io.File)`

### setSelectedFile

    public void setSelectedFile(java.io.File selectedFile)

  Sets the selected file. If the file's parent directory is not the current directory, it changed the current directory to be the files parent directory.
  Parameters:
    `selectedFile` - the selected file
  See Also:
    `getSelectedFile()`

### getSelectedFiles

    public java.io.File[] getSelectedFiles()

  Returns a list of selected files if the filechooser is set to allow multi-selection.

### setSelectedFiles

    public void setSelectedFiles(java.io.File[] selectedFiles)

  Sets the list of selected files if the filechooser is set to allow multi-selection.

### getCurrentDirectory

    public java.io.File getCurrentDirectory()

  Returns the current directory.
  Returns:
    the current directory
  See Also:
    `setCurrentDirectory(java.io.File)`

### setCurrentDirectory

    public void setCurrentDirectory(java.io.File dir)

  Sets the current directory. Passing in null sets the filechooser to point to the users's home directory. If the file passed in as currentDirectory is not a directory, the parent of the file will be used as the currentDirectory. If the parent is not traversable, then it will walk up the parent tree until it finds a traversable direcotry, or hits the root of the file system.
  Parameters:
    `currentDirectory` - the current directory to point to
  See Also:
    `getCurrentDirectory()`

### changeToParentDirectory

    public void changeToParentDirectory()

  Changes the directory to be set to the parent of the current directory.
  See Also:
    `getCurrentDirectory()`

### rescanCurrentDirectory

    public void rescanCurrentDirectory()

  Tells the UI to rescan it's files list from the current directory.

### ensureFileIsVisible

    public void ensureFileIsVisible(java.io.File f)

  Make sure that the specified file is viewable, and not hidden.
  Parameters:
    `f` - a File object

### showOpenDialog

    public int showOpenDialog(java.awt.Component parent)

  Pops up an "Open File" file chooser dialog. Note that the text that appears in the approve button is determined by the L&F.
  Returns:
    the return state of the filechooser on popdown: CANCEL_OPTION, APPROVE_OPTION

### showSaveDialog

    public int showSaveDialog(java.awt.Component parent)

  Pops up a "Save File" file chooser dialog. Note that the text that appears in the approve button is determined by the L&F.
  Returns:
    the return state of the filechooser on popdown: CANCEL_OPTION, APPROVE_OPTION

### showDialog

    public int showDialog(java.awt.Component parent,
                          java.lang.String approveButtonText)

  Pops a custom file chooser dialog with a custom ApproveButton. e.g. filechooser.showDialog(parentWindow, "Run Application"); would pop up a filechooser with a "Run Application" button (instead of the normal "Save" or "Open" button). Alternatively, the following code will do the same thing: JFileChooser chooser = new JFileChooser(null); chooser.setApproveButtonText("Run Application"); chooser.showDialog(this, null); PENDING(jeff) - the following method should be added to the api: showDialog(Component parent);
  Parameters:
    `approveButtonText` - the text of the ApproveButton
  Returns:
    the return state of the filechooser on popdown: CANCEL_OPTION, APPROVE_OPTION

### getDialogType

    public int getDialogType()

  Returns the type of this dialog.
  Returns:
    the type of dialog to be displayed: OPEN_DIALOG, SAVE_DIALOG, CUSTOM_DIALOG
  See Also:
    `setDialogType(int)`

### setDialogType

    public void setDialogType(int dialogType)

  Sets the type of this dialog. Use OPEN_DIALOG when you want to bring up a filechooser that the user can use to open a file. Likewise, use SAVE_DIALOG for letting the user choose a file for saving. Use CUSTOM_DIALOG when you want to use the filechooser in a context other than "Open" or "Save". For instance, you might want to bring up a filechooser that allows the user to choose a file to execute. Note that you normally would not need to set the FileChooser to use CUSTOM_DIALOG since a call to setApproveButtonText does this for you.
  Parameters:
    `dialogType` - the type of dialog to be displayed: OPEN_DIALOG, SAVE_DIALOG, CUSTOM_DIALOG
  See Also:
    `getDialogType()`, `setApproveButtonText(java.lang.String)`

### setDialogTitle

    public void setDialogTitle(java.lang.String dialogTitle)

  Sets the string that goes in the FileChooser window's title bar.
  See Also:
    `getDialogTitle()`

### getDialogTitle

    public java.lang.String getDialogTitle()

  Gets the string that goes in the FileChooser's titlebar.
  See Also:
    `setDialogTitle(java.lang.String)`

### setApproveButtonToolTipText

    public void setApproveButtonToolTipText(java.lang.String toolTipText)

  Sets the tooltip text used in the ApproveButton. If null, the UI object will determine the button's text.
  Returns:
    the text used in the ApproveButton
  See Also:
    `setApproveButtonText(java.lang.String)`, `setDialogType(int)`, `showDialog(java.awt.Component, java.lang.String)`

### getApproveButtonToolTipText

    public java.lang.String getApproveButtonToolTipText()

  Returns the tooltip text used in the ApproveButton. If null, the UI object will determine the button's text.
  Returns:
    the text used in the ApproveButton
  See Also:
    `setApproveButtonText(java.lang.String)`, `setDialogType(int)`, `showDialog(java.awt.Component, java.lang.String)`

### getApproveButtonMnemonic

    public int getApproveButtonMnemonic()

  Returns the approve button's mnemonic.
  Returns:
    an int value for the mnemonic key
  See Also:
    `setApproveButtonMnemonic(int)`

### setApproveButtonMnemonic

    public void setApproveButtonMnemonic(int mnemonic)

  Sets the approve button's mnemonic using a numeric keycode.
  Parameters:
    `an` - int value for the mnemonic key
  See Also:
    `getApproveButtonMnemonic()`

### setApproveButtonMnemonic

    public void setApproveButtonMnemonic(char mnemonic)

  Sets the approve button's mnemonic using a character.
  Parameters:
    `an` - char value for the mnemonic key
  See Also:
    `getApproveButtonMnemonic()`

### setApproveButtonText

    public void setApproveButtonText(java.lang.String approveButtonText)

  Sets the text used in the ApproveButton in the FileChooserUI.
  Parameters:
    `approveButtonText` - the text used in the ApproveButton
  See Also:
    `getApproveButtonText()`, `setDialogType(int)`, `showDialog(java.awt.Component, java.lang.String)`

### getApproveButtonText

    public java.lang.String getApproveButtonText()

  Returns the text used in the ApproveButton in the FileChooserUI. If null, the UI object will determine the button's text. Typically, this would be "Open" or "Save".
  Returns:
    the text used in the ApproveButton
  See Also:
    `setApproveButtonText(java.lang.String)`, `setDialogType(int)`, `showDialog(java.awt.Component, java.lang.String)`

### getChoosableFileFilters

    public FileFilter[] getChoosableFileFilters()

  Gets the list of user choosable file filters
  Returns:
    a FileFilter array containing all the choosable file filters

### addChoosableFileFilter

    public void addChoosableFileFilter(FileFilter filter)

  Adds a filter to the list of user choosable file filters.
  Parameters:
    `filter` - the FileFilter to add to the choosable file filter list

### removeChoosableFileFilter

    public boolean removeChoosableFileFilter(FileFilter f)

  Removes a filter from the list of user choosable file filters. Returns true if the file filter was removed;

### resetChoosableFileFilters

    public void resetChoosableFileFilters()

  Resets the choosable file filter list to it's starting state. Normally, this removes all added file filters while leaving the AcceptAll file filter.
  See Also:
    `addChoosableFileFilter(javax.swing.filechooser.FileFilter)`, `getChoosableFileFilters()`, `removeChoosableFileFilter(javax.swing.filechooser.FileFilter)`

### getAcceptAllFileFilter

    public FileFilter getAcceptAllFileFilter()

  Returns the AcceptAll file filter (e.g. (All Files *.*) on windows).

### getAccessory

    public JComponent getAccessory()

  Return the accessory component.
  Returns:
    this JFileChooser's accessory component, or null
  See Also:
    `setAccessory(javax.swing.JComponent)`

### setAccessory

    public void setAccessory(JComponent newAccessory)

  Sets the accessory component. An accessory is often used to show a preview image of the selected file; however, it can be used for anything that the programmer wishes - such as extra custom file chooser controls. Note: if there was a previous accessory, you should unregister any listeners that the accessory might have registered with the file chooser.

### setFileSelectionMode

    public void setFileSelectionMode(int mode)

  Sets the FileChooser to allow the user to just select files, just select directories, or select both files and directetories.
  Parameters:
    `dialogType` - the type of dialog to be displayed: FILES_ONLY, DIRECTORIES_ONLY, FILES_AND_DIRECTORIES
  See Also:
    `getFileSelectionMode()`

### getFileSelectionMode

    public int getFileSelectionMode()

  Returns the current file-selection mode.
  Parameters:
    `an` - int indicating the type of dialog to be displayed: FILES_ONLY, DIRECTORIES_ONLY, FILES_AND_DIRECTORIES
  See Also:
    `setFileSelectionMode(int)`

### isFileSelectionEnabled

    public boolean isFileSelectionEnabled()

  Convenience call that determines if files are selectable based on the current file selection mode
  See Also:
    `setFileSelectionMode(int)`, `getFileSelectionMode()`

### isDirectorySelectionEnabled

    public boolean isDirectorySelectionEnabled()

  Convenience call that determines if directories are selectable based on the current file selection mode
  See Also:
    `setFileSelectionMode(int)`, `getFileSelectionMode()`

### setMultiSelectionEnabled

    public void setMultiSelectionEnabled(boolean b)

  Sets the filechooser to allow multiple file selections. NOTE: this functionality is not yet implemented in the current L&Fs.
  See Also:
    `isMultiSelectionEnabled()`

### isMultiSelectionEnabled

    public boolean isMultiSelectionEnabled()

  Returns true if multiple files can be selected.
  Returns:
    true if multiple files can be selected.
  See Also:
    `setMultiSelectionEnabled(boolean)`

### isFileHidingEnabled

    public boolean isFileHidingEnabled()

  If true, hidden files are not shown in the filechooser
  Returns:
    the status of the file hiding property
  See Also:
    `setFileHidingEnabled(boolean)`

### setFileHidingEnabled

    public void setFileHidingEnabled(boolean b)

  Sets file hiding on or off. If true, hidden files are not shown in the filechooser. The job of determining which files are show is done by the FileView.
  Parameters:
    `b` - the boolean value that determines whether file hiding is turned on or not.
  See Also:
    `isFileHidingEnabled()`

### setFileFilter

    public void setFileFilter(FileFilter filter)

  Sets the current File Filter. The file filter is used by the filechooser to filter out files from view from the user.
  Parameters:
    `filter` - the new current file filter to use
  See Also:
    `getFileFilter()`

### getFileFilter

    public FileFilter getFileFilter()

  Returns the currently selected file filter.
  Returns:
    the current file filter.
  See Also:
    `setFileFilter(javax.swing.filechooser.FileFilter)`, `addChoosableFileFilter(javax.swing.filechooser.FileFilter)`

### setFileView

    public void setFileView(FileView fileView)

  Sets the file view to used to retrieve UI information, such as the icon that represents a file or the type description of a file.
  See Also:
    `getFileView()`

### getFileView

    public FileView getFileView()

  Returns the current file view.
  See Also:
    `setFileView(javax.swing.filechooser.FileView)`

### getName

    public java.lang.String getName(java.io.File f)

  Returns the file name.
  See Also:
    `FileView.getName(java.io.File)`

### getDescription

    public java.lang.String getDescription(java.io.File f)

  Returns the file description.
  See Also:
    `FileView.getDescription(java.io.File)`

### getTypeDescription

    public java.lang.String getTypeDescription(java.io.File f)

  Returns the file type.
  See Also:
    `FileView.getTypeDescription(java.io.File)`

### getIcon

    public Icon getIcon(java.io.File f)

  Returns the icon for this file or type of file, depending on the system.
  See Also:
    `FileView.getIcon(java.io.File)`

### isTraversable

    public boolean isTraversable(java.io.File f)

  Returns true if the file (directory) can be visited. Returns false if the directory cannot be traversed.
  See Also:
    `FileView.isTraversable(java.io.File)`

### accept

    public boolean accept(java.io.File f)

  Returns true if the file should be displayed.
  See Also:
    `FileFilter.accept(java.io.File)`

### setFileSystemView

    public void setFileSystemView(FileSystemView fsv)

  Sets the file system view which the JFileChooser uses to access and create file system resouces, such as finding the floppy drive and getting a list of root drives.
  See Also:
    `FileSystemView`

### getFileSystemView

    public FileSystemView getFileSystemView()

  Returns the file system view.
  Returns:
    the FileSystemView object
  See Also:
    `setFileSystemView(javax.swing.filechooser.FileSystemView)`

### approveSelection

    public void approveSelection()

  Called by the UI when the user hits the approve (AKA "Open" or "Save") button. This can also by called by the programmer.

### cancelSelection

    public void cancelSelection()

  Called by the UI when the user hits the cancel button. This can also be called by the programmer.

### addActionListener

    public void addActionListener(java.awt.event.ActionListener l)

  adds an ActionListener to the button

### removeActionListener

    public void removeActionListener(java.awt.event.ActionListener l)

  removes an ActionListener from the button

### fireActionPerformed

    protected void fireActionPerformed(java.lang.String command)

  Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
  See Also:
    `EventListenerList`

### updateUI

    public void updateUI()

  Notification from the UIFactory that the L&F has changed.
  Overrides:
    updateUI in class JComponent
  See Also:
    `JComponent.updateUI()`

### getUIClassID

    public java.lang.String getUIClassID()

  Returns a string that specifies the name of the L&F class that renders this component.
  Returns:
    "ButtonUI"
  Overrides:
    getUIClassID in class JComponent
  See Also:
    `JComponent.getUIClassID()`, `UIDefaults.getUI(javax.swing.JComponent)`

### getUI

    public FileChooserUI getUI()

  Gets the UI object which implements the L&F for this component.
  Returns:
    the FileChooserUI object that implements the FileChooserUI L&F

### paramString

    protected java.lang.String paramString()

  Returns a string representation of this JFileChooser. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be `null`.

  Overriding paramString() to provide information about the specific new aspects of the JFC components.

  Returns:
    a string representation of this JFileChooser.
  Overrides:
    paramString in class JComponent

### getAccessibleContext

    public AccessibleContext getAccessibleContext()

  Get the AccessibleContext associated with this JFileChooser
  Specified by:
    getAccessibleContext in interface Accessible
  Returns:
    the AccessibleContext of this JFileChooser
  Overrides:
    getAccessibleContext in class JComponent

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.