charvax.swing
Class JFileChooser
public class JFileChooser
The JFileChooser class displays a dialog from which the user can choose
a file. The dialog is always modal (i.e. the user cannot interact
with any other windows until he closes the dialog).
The dialog is displayed by calling its showDialog() method, which blocks
until the dialog is closed (by the user pressing the Approve or Cancel
buttons, or by pressing ENTER while the focus is in the "Filename" field).
After the dialog has been closed, the program can find out what
File was selected by calling the getSelectedFile() method.
The labels of the buttons that are displayed in the JFileChooser
can be customized by changing the following static variables:
-
PARENT_DIRECTORY_LABEL
-
NEW_DIRECTORY_LABEL
-
APPROVE_LABEL
-
CANCEL_LABEL
"Accelerator keys" can also be set for the buttons. For example,
to set the F1 key to have the same effect as pressing the CANCEL
button, call the following code before using the JFileChooser:
JFileChooser.CANCEL_LABEL = "Cancel (F1)";
JFileChooser.CANCEL_ACCELERATOR = KeyEvent.VK_F1;
Note that after the buttons have been customized, they stay customized
for all future invocations of JFileChooser (until they are re-customized
to some other value).
BOTTOM_ALIGNMENT , CENTER_ALIGNMENT , LEFT_ALIGNMENT , RIGHT_ALIGNMENT , TOP_ALIGNMENT , _alignmentX , _alignmentY , _background , _cursesColor , _enabled , _focusListeners , _foreground , _keyListeners , _origin , _parent , _visible |
JFileChooser() - Constructs a JFileChooser pointing to the user's home directory.
|
JFileChooser(File currentDirectory_) - Constructs a JFileChooser pointing to the specified directory.
|
JFileChooser(String currentDirectoryPath_) - Constructs a JFileChooser with the specified pathname.
|
addFocusListener , addKeyListener , contains , contains , debug , draw , getAlignmentX , getAlignmentY , getAncestorWindow , getBackground , getBounds , getCursesColor , getForeground , getHeight , getLocation , getLocationOnScreen , getName , getParent , getSize , getWidth , hasFocus , hide , invalidate , isDisplayed , isEnabled , isFocusTraversable , isTotallyObscured , isValid , isVisible , minimumSize , processEvent , processFocusEvent , processKeyEvent , processMouseEvent , repaint , requestFocus , requestSync , setBackground , setBounds , setBounds , setBounds , setEnabled , setForeground , setLocation , setLocation , setName , setParent , setVisible , show , validate , validateCursesColor |
APPROVE_ACCELERATOR
public static int APPROVE_ACCELERATOR
APPROVE_LABEL
public static String APPROVE_LABEL
APPROVE_OPTION
public static final int APPROVE_OPTION
CANCEL_ACCELERATOR
public static int CANCEL_ACCELERATOR
CANCEL_LABEL
public static String CANCEL_LABEL
CANCEL_OPTION
public static final int CANCEL_OPTION
DIRECTORIES_ONLY
public static final int DIRECTORIES_ONLY
ERROR_OPTION
public static final int ERROR_OPTION
FILES_AND_DIRECTORIES
public static final int FILES_AND_DIRECTORIES
FILES_ONLY
public static final int FILES_ONLY
NEW_DIRECTORY_ACCELERATOR
public static int NEW_DIRECTORY_ACCELERATOR
NEW_DIRECTORY_LABEL
public static String NEW_DIRECTORY_LABEL
PARENT_DIRECTORY_ACCELERATOR
public static int PARENT_DIRECTORY_ACCELERATOR
PARENT_DIRECTORY_LABEL
public static String PARENT_DIRECTORY_LABEL
_COLS
protected static final int _COLS
_ROWS
protected static final int _ROWS
_approveButtonText
protected String _approveButtonText
_cancelWasPressed
protected boolean _cancelWasPressed
_currentDirectory
protected File _currentDirectory
The current directory shown in the dialog.
_dirList
protected charvax.swing.JFileChooser.DirList _dirList
_fileSelectionMode
protected int _fileSelectionMode
_filelisteners
protected Vector _filelisteners
_location
protected String _location
_title
protected String _title
JFileChooser
public JFileChooser()
Constructs a JFileChooser pointing to the user's home directory.
JFileChooser
public JFileChooser(File currentDirectory_)
Constructs a JFileChooser pointing to the specified directory.
Passing in a null parameter causes the JFileChooser to point to
the user's home directory.
JFileChooser
public JFileChooser(String currentDirectoryPath_)
Constructs a JFileChooser with the specified pathname. Passing a value
of null
causes the file chooser to point to the user's
home directory.
addFileChooserListener
protected void addFileChooserListener(charvax.swing.JFileChooser.FileChooserListener l)
fireFileChooserEvent
protected void fireFileChooserEvent()
getCurrentDirectory
public File getCurrentDirectory()
Returns the currently displayed directory.
getFileFilter
public FileFilter getFileFilter()
Returns the currently selected file filter.
getFileSelectionMode
public int getFileSelectionMode()
Returns the current file-selection mode.
- the file-selection mode, one of the following:
JFileChooser.FILES_ONLY
JFileChooser.DIRECTORIES_ONLY
JFileChooser.FILES_AND_DIRECTORIES
getHeight
public int getHeight()
Required to implement abstract method of JComponent (never used).
- getHeight in interface Component
getSelectedFile
public File getSelectedFile()
Get the File selected by the user. If the user pressed Cancel,
the return value is null.
getSize
public Dimension getSize()
Required to implement abstract method of JComponent (never used).
- getSize in interface Component
getWidth
public int getWidth()
Required to implement abstract method of JComponent (never used).
- getWidth in interface Component
setCurrentDirectory
public void setCurrentDirectory(File dir_)
Set the current directory. Passing a parameter of null
cause the JFileChooser to point to the user's home directory.
setDialogTitle
public void setDialogTitle(String title_)
setFileFilter
public void setFileFilter(FileFilter filter_)
Sets the current file filter. The file filter is used by the
file chooser to filter out files from the user's view.
setFileSelectionMode
public void setFileSelectionMode(int mode_)
Sets the JFileChooser
to allow the user to select
files only directories only, or files and directories. The default
is JFileChooser.FILES_ONLY.
setSelectedFile
public void setSelectedFile(File file_)
showDialog
public int showDialog(Component parent_,
String approveButtonText_)
Pops up a custom file chooser dialog with a custom approve button.
parent_
- the parent component of the dialog; can be
null
.approveButtonText_
- the custom text string to display in the
Approve button.
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION
showOpenDialog
public int showOpenDialog(Component parent_)
Pops up a "Open File" file chooser dialog; this is a convenience
method and is equivalent to showDialog(Component, "Open").
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION
showSaveDialog
public int showSaveDialog(Component parent_)
Pops up a "Save File" file chooser dialog; this is a convenience
method and is equivalent to showDialog(Component, "Save").
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileChooser.ERROR_OPTION