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).
|
|
|
|