javax.swing

Class JFileChooser

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class JFileChooser
extends JComponent
implements Accessible

A component that provides the user a dialog box to browse through a filesystem and choose one or more files or directories. A JFileChooser can be configured to filter the displayed file list by adding a FileFilter instance using addChoosableFileFilter(FileFilter). Additional components can be embedded in the file chooser using setAccessory(JComponent). The JFileChooser properties also provide mechanisms to customize the behaviour of the file chooser.
See Also:
Serialized Form

Nested Class Summary

protected class
JFileChooser.AccessibleJFileChooser
Provides the accessibility features for the JFileChooser component.

Nested classes/interfaces inherited from class javax.swing.JComponent

JComponent.AccessibleJComponent

Nested classes/interfaces inherited from class java.awt.Container

Container.AccessibleAWTContainer

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

static String
ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
The name of the 'accept all file filter used' property.
static String
ACCESSORY_CHANGED_PROPERTY
The name of the 'accessory' property.
static String
APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
The name of the property for the approve button mnemonic.
static String
APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
The name of the property for the approve button text.
static String
APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
The name of the property for the approve button tool tip text.
static int
APPROVE_OPTION
A return value indicating the file chooser has been closed by approving the selection.
static String
APPROVE_SELECTION
Action command string for approving the current selection.
static int
CANCEL_OPTION
A return value indicating the file chooser has been closed by cancelling.
static String
CANCEL_SELECTION
Action command string for cancelling the current selection.
static String
CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
The name of the 'choosable file filters' property.
static String
CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
The name of the property for control button visibility.
static int
CUSTOM_DIALOG
A dialog type for some custom purpose.
static String
DIALOG_TITLE_CHANGED_PROPERTY
The name of the 'dialog title' property.
static String
DIALOG_TYPE_CHANGED_PROPERTY
The name of the 'dialog type' property.
static int
DIRECTORIES_ONLY
A selection mode constant indicating acceptance of directories only.
static String
DIRECTORY_CHANGED_PROPERTY
The name of the property for the current directory.
static int
ERROR_OPTION
A return value indicating the file chooser has been closed by some error.
static int
FILES_AND_DIRECTORIES
A selection mode constant indicating acceptance of files and directories.
static int
FILES_ONLY
A selection mode constant indicating acceptance of files only.
static String
FILE_FILTER_CHANGED_PROPERTY
The name of the 'file filter' property.
static String
FILE_HIDING_CHANGED_PROPERTY
The name of the 'file hiding enabled' property.
static String
FILE_SELECTION_MODE_CHANGED_PROPERTY
The name of the 'file selection mode' property.
static String
FILE_SYSTEM_VIEW_CHANGED_PROPERTY
The name of the 'file system view' property.
static String
FILE_VIEW_CHANGED_PROPERTY
The name of the 'file view' property.
static String
MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
The name of the property for multi-selection.
static int
OPEN_DIALOG
A dialog type for selecting a file to open.
static int
SAVE_DIALOG
A dialog type for selecting a file to save.
static String
SELECTED_FILES_CHANGED_PROPERTY
The name of the property for the selected files.
static String
SELECTED_FILE_CHANGED_PROPERTY
The name of the property for the selected file.
protected AccessibleContext
accessibleContext
The accessible context.

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

JFileChooser()
Creates a new JFileChooser object.
JFileChooser(File currentDirectory)
Creates a new JFileChooser object.
JFileChooser(File currentDirectory, FileSystemView fsv)
Creates a new JFileChooser object.
JFileChooser(String currentDirectoryPath)
Creates a new JFileChooser object.
JFileChooser(String currentDirectoryPath, FileSystemView fsv)
Creates a new JFileChooser object with the specified directory and FileSystemView.
JFileChooser(FileSystemView fsv)
Creates a new JFileChooser object.

Method Summary

boolean
accept(File f)
Returns true if the file is accepted by the current file filter.
void
addActionListener(ActionListener l)
Adds an ActionListener to the file chooser.
void
addChoosableFileFilter(FileFilter filter)
Adds a file filter to the list of available filters and sends a PropertyChangeEvent (with the property name CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) to all registered listeners.
void
approveSelection()
Approves the selection.
void
cancelSelection()
Cancels the selection.
void
changeToParentDirectory()
Called by the UI delegate when the parent directory is changed.
protected JDialog
createDialog(Component parent)
Creates a modal dialog in which to display the file chooser.
void
ensureFileIsVisible(File f)
Ensures the the specified file is visible (this is handled by the UI delegate).
protected void
fireActionPerformed(String command)
Sends an @link {ActionEvent} to all registered listeners.
FileFilter
getAcceptAllFileFilter()
Returns the 'accept all' file filter from the UI delegate.
AccessibleContext
getAccessibleContext()
Returns the object that provides accessibility features for this JFileChooser component.
JComponent
getAccessory()
Returns the accessory component for the file chooser.
ActionListener[]
getActionListeners()
Returns the action listeners registered with this file chooser.
int
getApproveButtonMnemonic()
Returns the approve button mnemonic, or zero if no mnemonic has been set.
String
getApproveButtonText()
Returns the approve button text.
String
getApproveButtonToolTipText()
Returns the tool tip text for the approve button.
FileFilter[]
getChoosableFileFilters()
Returns the available file filters for this file chooser.
boolean
getControlButtonsAreShown()
Returns the flag that controls whether or not the control buttons are shown on the file chooser.
File
getCurrentDirectory()
Returns the current directory.
String
getDescription(File f)
Returns the description of the file, generated by the current (or default) FileView.
String
getDialogTitle()
Returns the dialog title.
int
getDialogType()
Returns the type of file chooser.
boolean
getDragEnabled()
Returns true if dragging is enabled.
FileFilter
getFileFilter()
Returns the file filter.
int
getFileSelectionMode()
Returns the file selection mode, one of: FILES_ONLY, DIRECTORIES_ONLY or FILES_AND_DIRECTORIES.
FileSystemView
getFileSystemView()
Returns the file system view being used by this file chooser.
FileView
getFileView()
Returns the custom FileView for the file chooser.
Icon
getIcon(File f)
Returns the icon provided by the current (or default) FileView.
String
getName(File f)
Returns the name of the file, generated by the current (or default) FileView.
File
getSelectedFile()
Returns the selected file, if there is one.
File[]
getSelectedFiles()
Returns the selected file or files in an array.
String
getTypeDescription(File f)
Returns the type description for the file, generated by the current (or default) FileView.
FileChooserUI
getUI()
Returns the UI delegate for the component.
String
getUIClassID()
Returns the UI delegate class identifier.
boolean
isAcceptAllFileFilterUsed()
Returns the flag that controls whether or not the 'accept all' file filter is included in the list of filters.
boolean
isDirectorySelectionEnabled()
Returns true if directory selection is enabled, and false otherwise.
boolean
isFileHidingEnabled()
Returns true if hidden files are to be hidden, and false otherwise.
boolean
isFileSelectionEnabled()
Returns true if file selection is enabled, and false otherwise.
boolean
isMultiSelectionEnabled()
Returns true if multiple selections are allowed within this file chooser, and false otherwise.
boolean
isTraversable(File f)
Returns true if the file is traversable, and false otherwise.
protected String
paramString()
Returns a string describing the attributes for the JFileChooser component, for use in debugging.
void
removeActionListener(ActionListener l)
Removes an ActionListener from this file chooser.
boolean
removeChoosableFileFilter(FileFilter f)
Removes a file filter from the list of available filters and sends a PropertyChangeEvent (with the property name CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) to all registered listeners.
void
rescanCurrentDirectory()
Rescans the current directory (this is handled by the UI delegate).
void
resetChoosableFileFilters()
Clears the list of choosable file filters and installs the 'accept all' filter from the UI delegate.
void
setAcceptAllFileFilterUsed(boolean b)
Sets the flag that controls whether or not the 'accept all' file filter is included in the list of filters, and sends a PropertyChangeEvent (with the property name ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY) to all registered listeners.
void
setAccessory(JComponent newAccessory)
Sets the accessory component for the file chooser and sends a PropertyChangeEvent to all registered listeners.
void
setApproveButtonMnemonic(char mnemonic)
Sets the mnemonic for the approve button and sends a PropertyChangeEvent (with the property name APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY) to all registered listeners.
void
setApproveButtonMnemonic(int mnemonic)
Sets the mnemonic for the approve button and sends a PropertyChangeEvent (with the property name APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY) to all registered listeners.
void
setApproveButtonText(String approveButtonText)
Sets the approve button text and fires a PropertyChangeEvent (with the property name APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) to all registered listeners.
void
setApproveButtonToolTipText(String toolTipText)
Sets the tool tip text for the approve button and sends a PropertyChangeEvent (with the property name APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY) to all registered listeners.
void
setControlButtonsAreShown(boolean b)
Sets the flag that controls whether or not the control buttons are shown and, if it changes, sends a PropertyChangeEvent (with the property name CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY) to all registered listeners.
void
setCurrentDirectory(File dir)
Sets the current directory and fires a PropertyChangeEvent (with the property name DIRECTORY_CHANGED_PROPERTY) to all registered listeners.
void
setDialogTitle(String dialogTitle)
Sets the dialog title and sends a PropertyChangeEvent (with the property name DIALOG_TITLE_CHANGED_PROPERTY) to all registered listeners.
void
setDialogType(int dialogType)
Sets the dialog type and fires a PropertyChangeEvent (with the property name DIALOG_TYPE_CHANGED_PROPERTY) to all registered listeners.
void
setDragEnabled(boolean b)
Sets the dragEnabled property, this disables/enables automatic drag handling (drag and drop) on this component.
void
setFileFilter(FileFilter filter)
Sets the file filter and sends a PropertyChangeEvent (with the property name FILE_FILTER_CHANGED_PROPERTY) to all registered listeners.
void
setFileHidingEnabled(boolean b)
Sets the flag that controls whether or not hidden files are displayed, and sends a PropertyChangeEvent (with the property name FILE_HIDING_CHANGED_PROPERTY) to all registered listeners.
void
setFileSelectionMode(int mode)
Sets the file selection mode and sends a PropertyChangeEvent to all registered listeners.
void
setFileSystemView(FileSystemView fsv)
Sets the file system view for the file chooser and sends a PropertyChangeEvent to all registered listeners.
void
setFileView(FileView fileView)
Sets a custom FileView for the file chooser and sends a PropertyChangeEvent to all registered listeners.
void
setMultiSelectionEnabled(boolean b)
Sets the flag that controls whether multiple selections are allowed in this filechooser and sends a PropertyChangeEvent (with the property name MULTI_SELECTION_ENABLED_CHANGED_PROPERTY) to all registered listeners.
void
setSelectedFile(File file)
Sets the selected file and sends a PropertyChangeEvent to all registered listeners.
void
setSelectedFiles(File[] selectedFiles)
Sets the selected files and sends a PropertyChangeEvent (with the name SELECTED_FILES_CHANGED_PROPERTY) to all registered listeners.
protected void
setup(FileSystemView view)
Sets up the file chooser.
int
showDialog(Component parent, String approveButtonText)
Displays the file chooser in a modal dialog using the CUSTOM_DIALOG type.
int
showOpenDialog(Component parent)
Displays the file chooser in a modal dialog using the OPEN_DIALOG type.
int
showSaveDialog(Component parent)
Displays the file chooser in a modal dialog using the SAVE_DIALOG type.
void
updateUI()
Installs the UI delegate for the current look and feel.

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, 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, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY

public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
The name of the 'accept all file filter used' property.
Field Value:
"acceptAllFileFilterUsedChanged"

ACCESSORY_CHANGED_PROPERTY

public static final String ACCESSORY_CHANGED_PROPERTY
The name of the 'accessory' property.
Field Value:
"AccessoryChangedProperty"

APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY

public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
The name of the property for the approve button mnemonic.
Field Value:
"ApproveButtonMnemonicChangedProperty"

APPROVE_BUTTON_TEXT_CHANGED_PROPERTY

public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
The name of the property for the approve button text.
Field Value:
"ApproveButtonTextChangedProperty"

APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY

public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
The name of the property for the approve button tool tip text.
Field Value:
"ApproveButtonToolTipTextChangedProperty"

APPROVE_OPTION

public static final int APPROVE_OPTION
A return value indicating the file chooser has been closed by approving the selection.
Field Value:
0

APPROVE_SELECTION

public static final String APPROVE_SELECTION
Action command string for approving the current selection.
Field Value:
"ApproveSelection"

CANCEL_OPTION

public static final int CANCEL_OPTION
A return value indicating the file chooser has been closed by cancelling.
Field Value:
1

CANCEL_SELECTION

public static final String CANCEL_SELECTION
Action command string for cancelling the current selection.
Field Value:
"CancelSelection"

CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY

public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
The name of the 'choosable file filters' property.
Field Value:
"ChoosableFileFilterChangedProperty"

CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY

public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
The name of the property for control button visibility.
Field Value:
"ControlButtonsAreShownChangedProperty"

CUSTOM_DIALOG

public static final int CUSTOM_DIALOG
A dialog type for some custom purpose.
Field Value:
2

DIALOG_TITLE_CHANGED_PROPERTY

public static final String DIALOG_TITLE_CHANGED_PROPERTY
The name of the 'dialog title' property.
Field Value:
"DialogTitleChangedProperty"

DIALOG_TYPE_CHANGED_PROPERTY

public static final String DIALOG_TYPE_CHANGED_PROPERTY
The name of the 'dialog type' property.
Field Value:
"DialogTypeChangedProperty"

DIRECTORIES_ONLY

public static final int DIRECTORIES_ONLY
A selection mode constant indicating acceptance of directories only.
Field Value:
1

DIRECTORY_CHANGED_PROPERTY

public static final String DIRECTORY_CHANGED_PROPERTY
The name of the property for the current directory.
Field Value:
"directoryChanged"

ERROR_OPTION

public static final int ERROR_OPTION
A return value indicating the file chooser has been closed by some error.
Field Value:
-1

FILES_AND_DIRECTORIES

public static final int FILES_AND_DIRECTORIES
A selection mode constant indicating acceptance of files and directories.
Field Value:
2

FILES_ONLY

public static final int FILES_ONLY
A selection mode constant indicating acceptance of files only.
Field Value:
0

FILE_FILTER_CHANGED_PROPERTY

public static final String FILE_FILTER_CHANGED_PROPERTY
The name of the 'file filter' property.
Field Value:
"fileFilterChanged"

FILE_HIDING_CHANGED_PROPERTY

public static final String FILE_HIDING_CHANGED_PROPERTY
The name of the 'file hiding enabled' property.
Field Value:
"FileHidingChanged"

FILE_SELECTION_MODE_CHANGED_PROPERTY

public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY
The name of the 'file selection mode' property.
Field Value:
"fileSelectionChanged"

FILE_SYSTEM_VIEW_CHANGED_PROPERTY

public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
The name of the 'file system view' property.
Field Value:
"FileSystemViewChanged"

FILE_VIEW_CHANGED_PROPERTY

public static final String FILE_VIEW_CHANGED_PROPERTY
The name of the 'file view' property.
Field Value:
"fileViewChanged"

MULTI_SELECTION_ENABLED_CHANGED_PROPERTY

public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
The name of the property for multi-selection.
Field Value:
"MultiSelectionEnabledChangedProperty"

OPEN_DIALOG

public static final int OPEN_DIALOG
A dialog type for selecting a file to open.
Field Value:
0

SAVE_DIALOG

public static final int SAVE_DIALOG
A dialog type for selecting a file to save.
Field Value:
1

SELECTED_FILES_CHANGED_PROPERTY

public static final String SELECTED_FILES_CHANGED_PROPERTY
The name of the property for the selected files.
Field Value:
"SelectedFilesChangedProperty"

SELECTED_FILE_CHANGED_PROPERTY

public static final String SELECTED_FILE_CHANGED_PROPERTY
The name of the property for the selected file.
Field Value:
"SelectedFileChangedProperty"

accessibleContext

protected AccessibleContext accessibleContext
The accessible context.

Constructor Details

JFileChooser

public JFileChooser()
Creates a new JFileChooser object.

JFileChooser

public JFileChooser(File currentDirectory)
Creates a new JFileChooser object.
Parameters:
currentDirectory - the directory that should initially be shown in the filechooser (if null, the user's home directory is used).

JFileChooser

public JFileChooser(File currentDirectory,
                    FileSystemView fsv)
Creates a new JFileChooser object.
Parameters:
currentDirectory - the directory that should initially be shown in the filechooser (if null, the user's home directory is used).
fsv - the file system view (if null, the default file system view is used).

JFileChooser

public JFileChooser(String currentDirectoryPath)
Creates a new JFileChooser object.
Parameters:
currentDirectoryPath - the directory that should initially be shown in the filechooser (if null, the user's home directory is used).

JFileChooser

public JFileChooser(String currentDirectoryPath,
                    FileSystemView fsv)
Creates a new JFileChooser object with the specified directory and FileSystemView.
Parameters:
currentDirectoryPath - the directory that should initially be shown in the filechooser (if null, the user's home directory is used).
fsv - the file system view (if null, the default file system view is used).

JFileChooser

public JFileChooser(FileSystemView fsv)
Creates a new JFileChooser object.
Parameters:
fsv - the file system view (if null, the default file system view is used).

Method Details

accept

public boolean accept(File f)
Returns true if the file is accepted by the current file filter.
Parameters:
f - the file.
Returns:
A boolean.

addActionListener

public void addActionListener(ActionListener l)
Adds an ActionListener to the file chooser.
Parameters:
l - the listener.

addChoosableFileFilter

public void addChoosableFileFilter(FileFilter filter)
Adds a file filter to the list of available filters and sends a PropertyChangeEvent (with the property name CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) to all registered listeners.
Parameters:
filter - the filter (null permitted).

approveSelection

public void approveSelection()
Approves the selection. An ActionEvent is sent to all registered listeners.

cancelSelection

public void cancelSelection()
Cancels the selection. An ActionEvent is sent to all registered listeners.

changeToParentDirectory

public void changeToParentDirectory()
Called by the UI delegate when the parent directory is changed.

createDialog

protected JDialog createDialog(Component parent)
            throws HeadlessException
Creates a modal dialog in which to display the file chooser.
Parameters:
parent - the parent component.
Returns:
The dialog.
Throws:
HeadlessException - DOCUMENT ME!

ensureFileIsVisible

public void ensureFileIsVisible(File f)
Ensures the the specified file is visible (this is handled by the UI delegate).
Parameters:
f - the file.

fireActionPerformed

protected void fireActionPerformed(String command)
Sends an @link {ActionEvent} to all registered listeners.
Parameters:
command - the action command.

getAcceptAllFileFilter

public FileFilter getAcceptAllFileFilter()
Returns the 'accept all' file filter from the UI delegate.
Returns:
The 'accept all' file filter.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JFileChooser component.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface JComponent
Returns:
The accessible context (an instance of JFileChooser.AccessibleJFileChooser).

getAccessory

public JComponent getAccessory()
Returns the accessory component for the file chooser. The default value is null.
Returns:
The accessory component (possibly null).

getActionListeners

public ActionListener[] getActionListeners()
Returns the action listeners registered with this file chooser.
Returns:
An array of listeners.

getApproveButtonMnemonic

public int getApproveButtonMnemonic()
Returns the approve button mnemonic, or zero if no mnemonic has been set.
Returns:
The approve button mnemonic.

getApproveButtonText

public String getApproveButtonText()
Returns the approve button text.
Returns:
The approve button text (possibly null).

getApproveButtonToolTipText

public String getApproveButtonToolTipText()
Returns the tool tip text for the approve button.
Returns:
The tool tip text for the approve button.

getChoosableFileFilters

public FileFilter[] getChoosableFileFilters()
Returns the available file filters for this file chooser.
Returns:
The available file filters.

getControlButtonsAreShown

public boolean getControlButtonsAreShown()
Returns the flag that controls whether or not the control buttons are shown on the file chooser.
Returns:
A boolean.

getCurrentDirectory

public File getCurrentDirectory()
Returns the current directory.
Returns:
The current directory.

getDescription

public String getDescription(File f)
Returns the description of the file, generated by the current (or default) FileView.
Parameters:
f - the file.
Returns:
The file description.

getDialogTitle

public String getDialogTitle()
Returns the dialog title.
Returns:
The dialog title (possibly null).

getDialogType

public int getDialogType()
Returns the type of file chooser.

getDragEnabled

public boolean getDragEnabled()
Returns true if dragging is enabled.
Returns:
true if dragging is enabled.

getFileFilter

public FileFilter getFileFilter()
Returns the file filter.
Returns:
The file filter.

getFileSelectionMode

public int getFileSelectionMode()
Returns the file selection mode, one of: FILES_ONLY, DIRECTORIES_ONLY or FILES_AND_DIRECTORIES. The default is FILES_ONLY.
Returns:
The file selection mode.

getFileSystemView

public FileSystemView getFileSystemView()
Returns the file system view being used by this file chooser.
Returns:
The file system view.

getFileView

public FileView getFileView()
Returns the custom FileView for the file chooser.
Returns:
The file view (possibly null).

getIcon

public Icon getIcon(File f)
Returns the icon provided by the current (or default) FileView.
Parameters:
f - the file.
Returns:
An icon representing the file.

getName

public String getName(File f)
Returns the name of the file, generated by the current (or default) FileView.
Parameters:
f - the file.
Returns:
The file name.

getSelectedFile

public File getSelectedFile()
Returns the selected file, if there is one.
Returns:
The selected file (possibly null).

getSelectedFiles

public File[] getSelectedFiles()
Returns the selected file or files in an array. If no files are selected, an empty array is returned.
Returns:
An array of the selected files (possibly empty).

getTypeDescription

public String getTypeDescription(File f)
Returns the type description for the file, generated by the current (or default) FileView.
Parameters:
f - the file.
Returns:
The file type description.

getUI

public FileChooserUI getUI()
Returns the UI delegate for the component.
Returns:
The UI delegate.

getUIClassID

public String getUIClassID()
Returns the UI delegate class identifier.
Overrides:
getUIClassID in interface JComponent
Returns:
FileChooserUI.

isAcceptAllFileFilterUsed

public boolean isAcceptAllFileFilterUsed()
Returns the flag that controls whether or not the 'accept all' file filter is included in the list of filters.
Returns:
A boolean.

isDirectorySelectionEnabled

public boolean isDirectorySelectionEnabled()
Returns true if directory selection is enabled, and false otherwise. Directory selection is enabled when the file selection mode is DIRECTORIES_ONLY or FILES_AND_DIRECTORIES.
Returns:
true if file selection is enabled.

isFileHidingEnabled

public boolean isFileHidingEnabled()
Returns true if hidden files are to be hidden, and false otherwise.
Returns:
A boolean.

isFileSelectionEnabled

public boolean isFileSelectionEnabled()
Returns true if file selection is enabled, and false otherwise. File selection is enabled when the file selection mode is FILES_ONLY or FILES_AND_DIRECTORIES.
Returns:
true if file selection is enabled.

isMultiSelectionEnabled

public boolean isMultiSelectionEnabled()
Returns true if multiple selections are allowed within this file chooser, and false otherwise.
Returns:
A boolean.

isTraversable

public boolean isTraversable(File f)
Returns true if the file is traversable, and false otherwise.
Parameters:
f - the file or directory.
Returns:
A boolean.

paramString

protected String paramString()
Returns a string describing the attributes for the JFileChooser component, for use in debugging. The return value is guaranteed to be non-null, but the format of the string may vary between implementations.
Overrides:
paramString in interface JComponent
Returns:
A string describing the attributes of the JFileChooser.

removeActionListener

public void removeActionListener(ActionListener l)
Removes an ActionListener from this file chooser.
Parameters:
l - the listener.

removeChoosableFileFilter

public boolean removeChoosableFileFilter(FileFilter f)
Removes a file filter from the list of available filters and sends a PropertyChangeEvent (with the property name CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) to all registered listeners.
Parameters:
f - the file filter.
Returns:
true if the filter was removed and false otherwise.

rescanCurrentDirectory

public void rescanCurrentDirectory()
Rescans the current directory (this is handled by the UI delegate).

resetChoosableFileFilters

public void resetChoosableFileFilters()
Clears the list of choosable file filters and installs the 'accept all' filter from the UI delegate.

setAcceptAllFileFilterUsed

public void setAcceptAllFileFilterUsed(boolean b)
Sets the flag that controls whether or not the 'accept all' file filter is included in the list of filters, and sends a PropertyChangeEvent (with the property name ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY) to all registered listeners.
Parameters:
b - the new value of the flag.

setAccessory

public void setAccessory(JComponent newAccessory)
Sets the accessory component for the file chooser and sends a PropertyChangeEvent to all registered listeners. The property name is ACCESSORY_CHANGED_PROPERTY.
Parameters:
newAccessory - the accessory component.

setApproveButtonMnemonic

public void setApproveButtonMnemonic(char mnemonic)
Sets the mnemonic for the approve button and sends a PropertyChangeEvent (with the property name APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY) to all registered listeners.
Parameters:
mnemonic - the mnemonic.

setApproveButtonMnemonic

public void setApproveButtonMnemonic(int mnemonic)
Sets the mnemonic for the approve button and sends a PropertyChangeEvent (with the property name APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY) to all registered listeners.
Parameters:
mnemonic - the mnemonic.

setApproveButtonText

public void setApproveButtonText(String approveButtonText)
Sets the approve button text and fires a PropertyChangeEvent (with the property name APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) to all registered listeners.
Parameters:
approveButtonText - the text (null permitted).

setApproveButtonToolTipText

public void setApproveButtonToolTipText(String toolTipText)
Sets the tool tip text for the approve button and sends a PropertyChangeEvent (with the property name APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY) to all registered listeners.
Parameters:
toolTipText - the text.

setControlButtonsAreShown

public void setControlButtonsAreShown(boolean b)
Sets the flag that controls whether or not the control buttons are shown and, if it changes, sends a PropertyChangeEvent (with the property name CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY) to all registered listeners.
Parameters:
b - the new value for the flag.

setCurrentDirectory

public void setCurrentDirectory(File dir)
Sets the current directory and fires a PropertyChangeEvent (with the property name DIRECTORY_CHANGED_PROPERTY) to all registered listeners. If dir is null, the current directory is set to the default directory returned by the file system view.
Parameters:
dir - the new directory (null permitted).

setDialogTitle

public void setDialogTitle(String dialogTitle)
Sets the dialog title and sends a PropertyChangeEvent (with the property name DIALOG_TITLE_CHANGED_PROPERTY) to all registered listeners.
Parameters:
dialogTitle - the dialog title (null permitted).

setDialogType

public void setDialogType(int dialogType)
Sets the dialog type and fires a PropertyChangeEvent (with the property name DIALOG_TYPE_CHANGED_PROPERTY) to all registered listeners.
Parameters:
dialogType - the dialog type (one of: OPEN_DIALOG, SAVE_DIALOG, CUSTOM_DIALOG).
Throws:
IllegalArgumentException - if dialogType is not valid.

setDragEnabled

public void setDragEnabled(boolean b)
Sets the dragEnabled property, this disables/enables automatic drag handling (drag and drop) on this component. The default value of the dragEnabled property is false. Some look and feels might not support automatic drag and drop; they will ignore this property.
Parameters:
b - - the new dragEnabled value

setFileFilter

public void setFileFilter(FileFilter filter)
Sets the file filter and sends a PropertyChangeEvent (with the property name FILE_FILTER_CHANGED_PROPERTY) to all registered listeners.
Parameters:
filter - the filter (null permitted).

setFileHidingEnabled

public void setFileHidingEnabled(boolean b)
Sets the flag that controls whether or not hidden files are displayed, and sends a PropertyChangeEvent (with the property name FILE_HIDING_CHANGED_PROPERTY) to all registered listeners.
Parameters:
b - the new value of the flag.

setFileSelectionMode

public void setFileSelectionMode(int mode)
Sets the file selection mode and sends a PropertyChangeEvent to all registered listeners. The property name is FILE_SELECTION_MODE_CHANGED_PROPERTY.
Parameters:
mode - the mode (FILES_ONLY, DIRECTORIES_ONLY or FILES_AND_DIRECTORIES).
Throws:
IllegalArgumentException - if the mode is invalid.

setFileSystemView

public void setFileSystemView(FileSystemView fsv)
Sets the file system view for the file chooser and sends a PropertyChangeEvent to all registered listeners.
Parameters:
fsv - the file system view.

setFileView

public void setFileView(FileView fileView)
Sets a custom FileView for the file chooser and sends a PropertyChangeEvent to all registered listeners. The property name is FILE_VIEW_CHANGED_PROPERTY.
Parameters:
fileView - the file view (null permitted).
See Also:
getFileView()

setMultiSelectionEnabled

public void setMultiSelectionEnabled(boolean b)
Sets the flag that controls whether multiple selections are allowed in this filechooser and sends a PropertyChangeEvent (with the property name MULTI_SELECTION_ENABLED_CHANGED_PROPERTY) to all registered listeners.
Parameters:
b - the new value of the flag.

setSelectedFile

public void setSelectedFile(File file)
Sets the selected file and sends a PropertyChangeEvent to all registered listeners. The property name is SELECTED_FILE_CHANGED_PROPERTY.
Parameters:
file - the file (null permitted).

setSelectedFiles

public void setSelectedFiles(File[] selectedFiles)
Sets the selected files and sends a PropertyChangeEvent (with the name SELECTED_FILES_CHANGED_PROPERTY) to all registered listeners.
Parameters:
selectedFiles - the selected files (null permitted).

setup

protected void setup(FileSystemView view)
Sets up the file chooser. This method is called by all the constructors.
Parameters:
view - the file system view (if null, the default file system view is used).

showDialog

public int showDialog(Component parent,
                      String approveButtonText)
            throws HeadlessException
Displays the file chooser in a modal dialog using the CUSTOM_DIALOG type.
Parameters:
parent - the parent component.
Returns:
A return value indicating how the dialog was closed (one of APPROVE_OPTION, CANCEL_OPTION and ERROR_OPTION).
Throws:
HeadlessException - DOCUMENT ME!

showOpenDialog

public int showOpenDialog(Component parent)
            throws HeadlessException
Displays the file chooser in a modal dialog using the OPEN_DIALOG type.
Parameters:
parent - the parent component.
Returns:
A return value indicating how the dialog was closed (one of APPROVE_OPTION, CANCEL_OPTION and ERROR_OPTION).
Throws:
HeadlessException - DOCUMENT ME!

showSaveDialog

public int showSaveDialog(Component parent)
            throws HeadlessException
Displays the file chooser in a modal dialog using the SAVE_DIALOG type.
Parameters:
parent - the parent component.
Returns:
A return value indicating how the dialog was closed (one of APPROVE_OPTION, CANCEL_OPTION and ERROR_OPTION).
Throws:
HeadlessException - DOCUMENT ME!

updateUI

public void updateUI()
Installs the UI delegate for the current look and feel.
Overrides:
updateUI in interface JComponent

JFileChooser.java -- Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.