|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object charva.awt.Component charvax.swing.JComponent charvax.swing.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).
Field Summary | |
protected java.lang.String |
_approveButtonText
|
protected boolean |
_cancelWasPressed
|
protected static int |
_COLS
|
protected java.io.File |
_currentDirectory
The current directory shown in the dialog. |
protected charvax.swing.JFileChooser.DirList |
_dirList
|
protected FileFilter |
_fileFilter
|
protected java.util.Vector |
_filelisteners
|
protected int |
_fileSelectionMode
|
protected java.lang.String |
_location
|
protected static int |
_ROWS
|
protected java.lang.String |
_title
|
static int |
APPROVE_ACCELERATOR
|
static java.lang.String |
APPROVE_LABEL
|
static int |
APPROVE_OPTION
|
static int |
CANCEL_ACCELERATOR
|
static java.lang.String |
CANCEL_LABEL
|
static int |
CANCEL_OPTION
|
static int |
DIRECTORIES_ONLY
|
static int |
ERROR_OPTION
|
static int |
FILES_AND_DIRECTORIES
|
static int |
FILES_ONLY
|
static int |
NEW_DIRECTORY_ACCELERATOR
|
static java.lang.String |
NEW_DIRECTORY_LABEL
|
static int |
PARENT_DIRECTORY_ACCELERATOR
|
static java.lang.String |
PARENT_DIRECTORY_LABEL
|
Fields inherited from class charvax.swing.JComponent |
_border |
Fields inherited from class charva.awt.Component |
_alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Constructor Summary | |
JFileChooser()
Constructs a JFileChooser pointing to the user's home directory. |
|
JFileChooser(java.io.File currentDirectory_)
Constructs a JFileChooser pointing to the specified directory. |
|
JFileChooser(java.lang.String currentDirectoryPath_)
Constructs a JFileChooser with the specified pathname. |
Method Summary | |
protected void |
addFileChooserListener(charvax.swing.JFileChooser.FileChooserListener l)
|
void |
debug(int level_)
|
protected void |
fireFileChooserEvent()
|
java.io.File |
getCurrentDirectory()
Returns the currently displayed directory. |
FileFilter |
getFileFilter()
Returns the currently selected file filter. |
int |
getFileSelectionMode()
Returns the current file-selection mode. |
int |
getHeight()
Required to implement abstract method of JComponent (never used). |
java.io.File |
getSelectedFile()
Get the File selected by the user. |
Dimension |
getSize()
Required to implement abstract method of JComponent (never used). |
int |
getWidth()
Required to implement abstract method of JComponent (never used). |
Dimension |
minimumSize()
Required to implement abstract method of JComponent (never used). |
void |
setCurrentDirectory(java.io.File dir_)
Set the current directory. |
void |
setDialogTitle(java.lang.String title_)
|
void |
setFileFilter(FileFilter filter_)
Sets the current file filter. |
void |
setFileSelectionMode(int mode_)
Sets the JFileChooser to allow the user to select
files only directories only, or files and directories. |
void |
setSelectedFile(java.io.File file_)
|
int |
showDialog(Component parent_,
java.lang.String approveButtonText_)
Pops up a custom file chooser dialog with a custom approve button. |
int |
showOpenDialog(Component parent_)
Pops up a "Open File" file chooser dialog; this is a convenience method and is equivalent to showDialog(Component, "Open"). |
int |
showSaveDialog(Component parent_)
Pops up a "Save File" file chooser dialog; this is a convenience method and is equivalent to showDialog(Component, "Save"). |
Methods inherited from class charvax.swing.JComponent |
draw, getBorder, getInsets, setBorder |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String _title
protected java.lang.String _approveButtonText
protected java.io.File _currentDirectory
protected charvax.swing.JFileChooser.DirList _dirList
protected java.lang.String _location
protected boolean _cancelWasPressed
protected int _fileSelectionMode
protected FileFilter _fileFilter
protected java.util.Vector _filelisteners
protected static final int _COLS
protected static final int _ROWS
public static final int FILES_ONLY
public static final int DIRECTORIES_ONLY
public static final int FILES_AND_DIRECTORIES
public static final int CANCEL_OPTION
public static final int APPROVE_OPTION
public static final int ERROR_OPTION
public static java.lang.String CANCEL_LABEL
public static java.lang.String APPROVE_LABEL
public static java.lang.String PARENT_DIRECTORY_LABEL
public static java.lang.String NEW_DIRECTORY_LABEL
public static int CANCEL_ACCELERATOR
public static int APPROVE_ACCELERATOR
public static int PARENT_DIRECTORY_ACCELERATOR
public static int NEW_DIRECTORY_ACCELERATOR
Constructor Detail |
public JFileChooser()
public JFileChooser(java.io.File currentDirectory_)
public JFileChooser(java.lang.String currentDirectoryPath_)
null
causes the file chooser to point to the user's
home directory.
Method Detail |
public void setCurrentDirectory(java.io.File dir_)
null
cause the JFileChooser to point to the user's home directory.
public java.io.File getCurrentDirectory()
public java.io.File getSelectedFile()
public void setSelectedFile(java.io.File file_)
public int showDialog(Component parent_, java.lang.String approveButtonText_)
parent_
- the parent component of the dialog; can be
null
.approveButtonText_
- the custom text string to display in the
Approve button.
public int showSaveDialog(Component parent_)
public int showOpenDialog(Component parent_)
public void setFileSelectionMode(int mode_)
JFileChooser
to allow the user to select
files only directories only, or files and directories. The default
is JFileChooser.FILES_ONLY.
public int getFileSelectionMode()
JFileChooser.FILES_ONLY
JFileChooser.DIRECTORIES_ONLY
JFileChooser.FILES_AND_DIRECTORIES
public void setDialogTitle(java.lang.String title_)
public void setFileFilter(FileFilter filter_)
public FileFilter getFileFilter()
public void debug(int level_)
debug
in class Component
public Dimension minimumSize()
minimumSize
in class Component
public Dimension getSize()
getSize
in class Component
public int getHeight()
getHeight
in class Component
public int getWidth()
getWidth
in class Component
protected void addFileChooserListener(charvax.swing.JFileChooser.FileChooserListener l)
protected void fireFileChooserEvent()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |