public class StandardFileChooser
extends javax.swing.JFileChooser
javax.swing.JFileChooser.AccessibleJFileChooser
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
context |
private static java.lang.String |
DEFAULT_CONTEXT |
private boolean |
fileShouldExist |
private boolean |
isCurDirSet |
private boolean |
modifyDir |
private static java.lang.String |
preemptFileName |
private static java.lang.String |
preemptFiltersRequired |
private static long |
preemptTimeout |
static java.lang.String |
PREFS |
private static java.util.HashMap<java.lang.String,java.io.File> |
recentDirs |
private static java.util.prefs.Preferences |
recentPathPreferences |
ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, accessibleContext, ACCESSORY_CHANGED_PROPERTY, APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, APPROVE_OPTION, APPROVE_SELECTION, CANCEL_OPTION, CANCEL_SELECTION, CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, CUSTOM_DIALOG, DIALOG_TITLE_CHANGED_PROPERTY, DIALOG_TYPE_CHANGED_PROPERTY, DIRECTORIES_ONLY, DIRECTORY_CHANGED_PROPERTY, ERROR_OPTION, FILE_FILTER_CHANGED_PROPERTY, FILE_HIDING_CHANGED_PROPERTY, FILE_SELECTION_MODE_CHANGED_PROPERTY, FILE_SYSTEM_VIEW_CHANGED_PROPERTY, FILE_VIEW_CHANGED_PROPERTY, FILES_AND_DIRECTORIES, FILES_ONLY, MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, OPEN_DIALOG, SAVE_DIALOG, SELECTED_FILE_CHANGED_PROPERTY, SELECTED_FILES_CHANGED_PROPERTY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
StandardFileChooser() |
StandardFileChooser(boolean isSaveDialog,
java.lang.String filters,
java.lang.String title) |
StandardFileChooser(int dialogType,
java.lang.String filters,
java.lang.String title) |
Modifier and Type | Method and Description |
---|---|
StandardFileChooser |
addFilters(java.lang.String filterSpecSet)
Adds a set of filter-specs to the list of file filters for the FileChooser.
|
void |
approveSelection() |
StandardFileChooser |
clearFilters()
Clear any existing filters.
|
java.lang.String |
getContext() |
static java.io.File |
getDefaultDir() |
java.lang.String |
getDefaultExtension() |
private static java.util.prefs.Preferences |
getDefaultPreferenceStorage() |
static java.lang.String |
getFileName(boolean forSave,
java.awt.Component parent,
java.lang.String title,
java.lang.String defaultPath,
java.lang.String filters,
java.lang.String context) |
static java.lang.String |
getFileName(boolean forSave,
java.awt.Component parent,
java.lang.String title,
java.lang.String defaultPath,
java.lang.String filters,
java.lang.String context,
boolean disableDirChange) |
boolean |
getFileShouldExist() |
static java.lang.String |
getOpenName(java.lang.String filters) |
static java.lang.String |
getOpenName(java.lang.String filters,
java.lang.String defaultPath) |
static java.lang.String |
getOpenName(java.lang.String filters,
java.lang.String defaultPath,
java.lang.String title,
java.lang.String context,
java.awt.Component parent) |
static java.io.File |
getRecentDir(java.lang.String context) |
static java.io.File |
getRecentDir(java.lang.String context,
boolean mustExist) |
static java.io.File |
getRecentDir(java.lang.String context,
boolean mustExist,
java.io.File defaultIfNotSet) |
static java.io.File |
getRecentDirOrDefault(java.lang.String context,
boolean mustExist) |
static java.lang.String |
getSaveName(java.lang.String filters) |
static java.lang.String |
getSaveName(java.lang.String filters,
java.lang.String defaultPath) |
static java.lang.String |
getSaveName(java.lang.String filters,
java.lang.String defaultPath,
java.lang.String title,
java.lang.String context,
java.awt.Component parent) |
java.io.File |
getSelectedFile()
Returns the selected file.
|
static void |
loadRecentPaths() |
static void |
loadRecentPaths(java.util.prefs.Preferences storage) |
boolean |
modifyDir()
Gets the property 'modifyDir', which affects whether the user's actions (i.e.
|
boolean |
passesFilter(java.io.File f) |
static void |
preemptNextFileNameRequest(java.lang.String file,
java.lang.String filters)
Causes the next call to getFileName to return with the specified file WITHOUT showing the dialog.
|
static void |
saveRecentPaths() |
static void |
saveRecentPaths(java.util.prefs.Preferences storage) |
StandardFileChooser |
setButtonText(java.lang.String text)
Set the text that appears on the accept (OK) button.
|
StandardFileChooser |
setContext(java.lang.String context)
Set the context for default startup folder.
|
static void |
setDefaultDir(java.io.File dir) |
StandardFileChooser |
setDefaultFile(java.io.File f) |
StandardFileChooser |
setDefaultFile(java.lang.String path) |
void |
setFileShouldExist(boolean fileShouldExist) |
StandardFileChooser |
setModifyDir(boolean modifyDir)
Sets the property 'modifyDir', which affects whether the user's actions (i.e.
|
static void |
setRecentDir(java.lang.String context,
java.io.File value) |
static void |
setRecentDir(java.lang.String context,
java.lang.String value) |
StandardFileChooser |
setStartDir(java.io.File dir) |
StandardFileChooser |
setStartDir(java.lang.String path) |
java.io.File |
showFileDialog(java.awt.Component parent)
Show the File Chooser and return the selected file path, if successful, or null if the user
cancels.
|
accept, addActionListener, addChoosableFileFilter, cancelSelection, changeToParentDirectory, createDialog, ensureFileIsVisible, fireActionPerformed, getAcceptAllFileFilter, getAccessibleContext, getAccessory, getActionListeners, getApproveButtonMnemonic, getApproveButtonText, getApproveButtonToolTipText, getChoosableFileFilters, getControlButtonsAreShown, getCurrentDirectory, getDescription, getDialogTitle, getDialogType, getDragEnabled, getFileFilter, getFileSelectionMode, getFileSystemView, getFileView, getIcon, getName, getSelectedFiles, getTypeDescription, getUI, getUIClassID, isAcceptAllFileFilterUsed, isDirectorySelectionEnabled, isFileHidingEnabled, isFileSelectionEnabled, isMultiSelectionEnabled, isTraversable, paramString, removeActionListener, removeChoosableFileFilter, rescanCurrentDirectory, resetChoosableFileFilters, setAcceptAllFileFilterUsed, setAccessory, setApproveButtonMnemonic, setApproveButtonMnemonic, setApproveButtonText, setApproveButtonToolTipText, setControlButtonsAreShown, setCurrentDirectory, setDialogTitle, setDialogType, setDragEnabled, setFileFilter, setFileHidingEnabled, setFileSelectionMode, setFileSystemView, setFileView, setMultiSelectionEnabled, setSelectedFile, setSelectedFiles, setup, showDialog, showOpenDialog, showSaveDialog, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private java.lang.String context
private static final java.lang.String DEFAULT_CONTEXT
private boolean fileShouldExist
private boolean isCurDirSet
private boolean modifyDir
private static java.lang.String preemptFileName
private static java.lang.String preemptFiltersRequired
private static long preemptTimeout
public static final java.lang.String PREFS
private static java.util.HashMap<java.lang.String,java.io.File> recentDirs
private static java.util.prefs.Preferences recentPathPreferences
public StandardFileChooser()
public StandardFileChooser(boolean isSaveDialog, java.lang.String filters, java.lang.String title)
public StandardFileChooser(int dialogType, java.lang.String filters, java.lang.String title)
public StandardFileChooser addFilters(java.lang.String filterSpecSet)
|
) and one or more
File Extensions, separated by semi-colons (;
). I.e.: Description|ext1[;ext2...]
Both the description and at least one extension are required and cannot be blank.
A "set" of filter-specs consists of one or more filter-specs separated by a bar. E.g.:
filter-spec_1[|filter-spec_2...]
i.e. Description|ext1_1[;ext1_2...]|Description2|ext2_1[;ext2_2...]
A blank filter-spec is allowed and will simply be ignored. So the following will result in
the addition of exactly two filters (despite the empty file-specs at the start, middle and end).
${ code |Description|ext1;ext2||Description2|ext1;ext2| }
However the following filter-spec set would raise an error, because the list of extensions is effectively blank.
(the ext1... would be interpreted as the start of the second filter-spec).
${ code Description||ext1;ext2 }
As a special case, the filter-specs "*" or "*|*" are both interpreted as the accept-all-files filter, i.e.
"All Files (*.*)"filterSpecSet
- public void approveSelection()
approveSelection
in class javax.swing.JFileChooser
public StandardFileChooser clearFilters()
JFileChooser.setAcceptAllFileFilterUsed(boolean)
with the value false would be more efficient
than clearing all filters.public java.lang.String getContext()
public static java.io.File getDefaultDir()
public java.lang.String getDefaultExtension()
private static java.util.prefs.Preferences getDefaultPreferenceStorage()
public static java.lang.String getFileName(boolean forSave, java.awt.Component parent, java.lang.String title, java.lang.String defaultPath, java.lang.String filters, java.lang.String context)
public static java.lang.String getFileName(boolean forSave, java.awt.Component parent, java.lang.String title, java.lang.String defaultPath, java.lang.String filters, java.lang.String context, boolean disableDirChange)
public boolean getFileShouldExist()
public static java.lang.String getOpenName(java.lang.String filters)
public static java.lang.String getOpenName(java.lang.String filters, java.lang.String defaultPath)
public static java.lang.String getOpenName(java.lang.String filters, java.lang.String defaultPath, java.lang.String title, java.lang.String context, java.awt.Component parent)
public static java.io.File getRecentDir(java.lang.String context)
public static java.io.File getRecentDir(java.lang.String context, boolean mustExist)
public static java.io.File getRecentDir(java.lang.String context, boolean mustExist, java.io.File defaultIfNotSet)
public static java.io.File getRecentDirOrDefault(java.lang.String context, boolean mustExist)
public static java.lang.String getSaveName(java.lang.String filters)
public static java.lang.String getSaveName(java.lang.String filters, java.lang.String defaultPath)
public static java.lang.String getSaveName(java.lang.String filters, java.lang.String defaultPath, java.lang.String title, java.lang.String context, java.awt.Component parent)
public java.io.File getSelectedFile()
setSelectedFile
or by a user action, such as
either typing the filename into the UI or selecting the
file from a list in the UI.getSelectedFile
in class javax.swing.JFileChooser
JFileChooser.setSelectedFile(java.io.File)
public static void loadRecentPaths()
public static void loadRecentPaths(java.util.prefs.Preferences storage)
public boolean modifyDir()
public boolean passesFilter(java.io.File f)
public static void preemptNextFileNameRequest(java.lang.String file, java.lang.String filters)
file
- The file to return when getSaveName is called.filters
- The filter string that should be used to restrict preemption.public static void saveRecentPaths()
public static void saveRecentPaths(java.util.prefs.Preferences storage)
public StandardFileChooser setButtonText(java.lang.String text)
text
- The text to display on the button.public StandardFileChooser setContext(java.lang.String context)
context
- public static void setDefaultDir(java.io.File dir)
public StandardFileChooser setDefaultFile(java.io.File f)
public StandardFileChooser setDefaultFile(java.lang.String path)
public void setFileShouldExist(boolean fileShouldExist)
public StandardFileChooser setModifyDir(boolean modifyDir)
modifyDir
- Set to True if the users actions should affect the recent directory stored for the current
context. Set to false if the system's recent directories should not be affected.public static void setRecentDir(java.lang.String context, java.io.File value)
public static void setRecentDir(java.lang.String context, java.lang.String value)
public StandardFileChooser setStartDir(java.io.File dir)
public StandardFileChooser setStartDir(java.lang.String path)
public java.io.File showFileDialog(java.awt.Component parent)