A
JFileChooser
is the interface to the Java Swing JFileChooser Component.
It is automatically used by a
JFileDialog,
which usually is the easiest way to present a
JFileChooser
to a user, but a
JFileDialog
does the job without offering any control over layout, so you sometimes
need to build your own screens (e.g., the Yoix installer) using a
JFileChooser.
Yoix programs normally interact with a
JFileChooser
using event handlers and by reading or writing the following fields:
| approvebuttonmnemonic |
An
int
key code that is used as a mnemonic for the filechooser's approval button.
Reading returns a snapshot of the current value.
Writing immediately changes the mnemonic to the new value.
| | approvebuttontext |
A
String
used to label the approval button used when choosing a file.
Reading returns a snapshot of the current text.
Writing immediately changes the text to the new value.
| | approvebuttontooltiptext |
A
String
used as a tooltip when the cursor is over the filechooser's approval button.
Reading returns a snapshot of the current tooltip text.
Writing immediately changes the tooltip text to the new value.
| | background |
The
Color
that is used to paint the background of the filechooser.
Reading returns a snapshot of the current color.
Writing immediately changes the background to the new color.
Storing
NULL
in
background
is special and means use the background of the nearest component
that contains the filechooser and was assigned a background color other than
NULL;
if no component qualifies the filechooser uses
VM.screen.background.
| | border |
An
Object
that should be a
Border,
Insets,
Number,
or
String
that describes the border that is drawn around this filechooser.
A
NULL
value, which is the default, means no border.
A
border
that is an
Insets
or
Number
is an easy way to describe margins
(i.e., an
EmptyBorder),
in units of 72 dots per inch, that are left around the sides of this filechooser.
A
border
that is a
String
is a quick way to surround this filechooser with a border that uses the
String
as its title.
Reading returns a snapshot of the current border.
Writing immediately sets the filechooser's border to the new value.
| | buttons |
An
int
that shows or hides the
CANCEL
and
APPROVE
buttons of the filechooser depending on whether the value is non-zero or zero, respectively.
Reading returns a snapshot of the current display status of the buttons.
Writing immediately changes the display status of the buttons.
| | cursor |
An
Object
that should be an
int,
Image,
or
String
that selects the cursor shown when the pointer is over the filechooser.
A
cursor
that is an
int
should be one of the cursors defined in the
yoix.awt.Cursor
dictionary.
A
cursor
that is an
Image
can describe the cursor using its
size
and
hotspot
fields and often draws it using its
paint
function.
A
cursor
that is a
String
should be the name of a cursor that is already defined in
yoix.awt.Cursor
or the name a local a file or URL that contains a GIF or JPEG image
that will be used as the cursor.
Reading returns the current cursor.
Writing immediately changes the filechooser's cursor to the new value.
Storing
STANDARD_CURSOR
(the default) or
NULL
in
cursor
is special and means use the cursor assigned to the nearest component
that contains the filechooser and was assigned a cursor other than
STANDARD_CURSOR;
if no component qualifies the filechooser uses
DEFAULT_CURSOR.
| | directory |
A
String
that names the directory where the filechooser is currently looking for files,
with
NULL
being a quick way to reference a system dependent directory (often the
user's home).
The
directory
and
file
fields in a filechooser are connected and changing either one usually affects the
current directory, however when a filechooser is created the
directory
field is always processed before the
file
field.
Reading
directory
returns the full pathname of the current directory.
Storing a value in
directory
updates the current directory and sets the selected file to
NULL.
Storing a value in
file
selects that file and updates the current directory based on the newly
selected file.
| | doublebuffered |
An
int
that is
1
when the filechooser uses double-buffering to draw itself,
0
when it does not, and starts with a default value that is
selected by Java for the filechooser.
Reading returns the current double-buffering behavior.
Writing immediately sets the filechooser's double-buffering behavior to the new value.
Note that double-buffering may be required when transparent components are used.
| | dragenabled |
An
int
that should be set to
1
when this filechooser wants to use the automatic drag handling that Swing provides
for some components, and
0
(the default)
when it does not.
Components that do not provide automatic drag handling always return
0
when their
dragenabled
field is read, so storing
1
in
dragenabled
should only be viewed as a request for a service that may not be available.
Swing components can always take complete control of their drag and drop
handling using their
transferhandler
field or special drag and drop event handlers.
| | enabled |
An
Object
that is
1
when the filechooser can respond to user input,
0
when it can not respond, and
NULL
(the default)
when the filechooser inherits the value from the nearest lightweight container,
like a
JPanel,
that contains the filechooser and has its
enabled
field set to something other than
NULL.
The top-level application window that contains the filechooser always gets the
final say, so disabling that window always disables the filechooser.
Reading returns the current state.
Writing immediately sets the filechooser's state to the new value.
| | file |
A
String,
when
multiplemode
is zero,
or an
Array,
when
multiplemode
is non-zero,
that names the file or files currently selected by the filechooser.
The
directory
and
file
fields in a filechooser are connected and changing either one can affect the
current selection, however when a filechooser is created the
directory
field is always processed before the
file
field.
Reading
file
returns the full pathname of each selected file or
NULL
if no file was selected or the Cancel button was hit.
Storing a value in
directory
updates the current directory and sets the selected file to
NULL.
Storing a value in
file
selects the specified file or files and updates the current directory based on new
selection.
| | fileselectionmode |
An
int
that should be
FILES_ONLY
when only files can be selected,
DIRECTORIES_ONLY
when only directories can be selected, and
FILES_AND_DIRECTORIES
(the default)
when files and directories can be selected.
Reading returns the current setting.
Writing immediately changes the selection mode that the filechooser is using.
| | filter |
A
String
that is the text describing the current file filter.
Reading returns the current setting.
Writing immediately changes the file filter to the first filter among the loaded filters whose
descriptor matches the supplied text.
Text that matches none of the filter descriptors is silently ignored.
| | filters |
An
Array,
organized in pairs, that provides a complete description of file filters
that are available for reducing the set of files (but not directories)
displayed by the filechooser.
The first entry in a pair is the
String
that is displayed by the filechooser as the description of that filter.
The second entry in the pair is the pattern, which can be supplied
as a
String
or
Regexp,
that is matched against individual files.
A pair that consists of two consecutive
NULL
entries is special and indicates that the "All Files" filter option
should be included, however the "All Files" entry is only displayed
once and it always is the last listed filter.
Setting
filters
to
NULL
indicates that only the "All Files" filter should be supplied.
Remember, directories are unaffected by the filters.
By default, the last filter in the list is active; the
filter
field can be used to make a different filter active.
Reading returns the current filter set.
Writing immediately resets the filter set.
assigned to the filechooser that is displayed by the filechooser.
| | focusowner |
A read-only
int
that is non-zero when the filechooser has the focus.
| | font |
The
Font,
or font name if it is a
String,
that is used whenever the filechooser paints text.
Reading returns a snapshot of the current font.
Writing immediately repaints all text displayed by the filechooser in the new font.
| | foreground |
The
Color
that is used whenever the filechooser paints text.
Reading returns a snapshot of the current color.
Writing immediately repaints all text displayed by the filechooser in the new color.
Storing
NULL
in
foreground
is special and means use the foreground of the nearest component
that contains the filechooser and was assigned a foreground color other than
NULL;
if no component qualifies the filechooser uses
VM.screen.foreground.
| | hiddenfiles |
An
int
that should be non-zero when hidden files should be displayed in the chooser and
zero otherwise.
Reading returns the current setting.
Writing immediately changes the display status of hidden files.
| | layer |
An
int,
often a small number between 0 and 99,
that identifies the depth of this filechooser when it is added to a
JLayeredPane
or
JDesktopPane.
Components assigned to lower numbered layers are drawn before
the components in higher numbered layers.
Writing immediately changes the filechooser's layer, which usually means the
JLayeredPane
or
JDesktopPane
that contains the filechooser will be repainted.
| | location |
A
Point
that determines the location of the filechooser
in a coordinate system that has its origin at the upper left corner
of the container closest to the filechooser (in the component hierarchy)
that actually contains it, positive x to the right, positive y down,
and a resolution of 72 dots per inch.
Reading returns a snapshot of the current location.
Writing is allowed, but layout managers usually get the final say, so setting
location
should be viewed as a request that may not be honored.
| | mode |
An
int
that should be
OPEN
(the default) or
LOAD
when the user is being asked to select a file that will be read and
SAVE
when the selected file will be written.
All three constants are defined in
yoix.swing.
Reading returns the current mode.
Writing immediately changes the filechooser's mode to the new value.
| | multiplemode |
A non-zero value indicates that multiple selections are possible, while a zero value indicates
that only one selection at a time is permissible.
Reading returns the current mode.
Writing immediately changes the behavior of the filechooser.
| | nextfocus |
An
Object
that is the component that receives the focus after this filechooser
when the focus traverses from one component to the next
(usually by means of the keyboard
TAB
character).
A
NULL
value indicates that the default Java focus traversal is in effect.
Reading returns the value last stored.
Writing immediately sets the new focus traversal behavior.
| | opaque |
An
Object
that is
1
when the filechooser is opaque,
0
when it is transparent, and
NULL
(the default)
when the filechooser inherits the value from the nearest component that
contains the filechooser and has its
opaque
field set to something other than
NULL.
| | popup |
A
JPopupMenu
that is associated with the filechooser.
Reading returns the current popup menu.
Writing immediately shows the popup menu at the point in the filechooser's coordinate
system specified by the popup menu's
location
field, assuming of course that the filechooser is showing on the screen.
Storing
TRUE
in the popup menu's
visible
field, which was added in release 1.2.0, is an easy way to show the
popup menu that currently belongs to the filechooser.
| | preferredsize |
A
Dimension
that is used by layout managers when they need to know the filechooser's
preferred size in units of 72 dots per inch.
A
NULL
value means the filechooser has no preference.
A non-positive height or width is allowed and simply means the filechooser
has no preference for that dimension.
Reading returns the current preferred size.
Writing changes the preferred size and immediately notifies
root.layoutmanager,
which means the components contained in
root
may be repositioned and resized.
| | requestfocus |
An
int
that can be used to request or transfer the keyboard focus.
Storing a non-zero value in
requestfocus
tries to get the focus.
Storing
0
tries to transfer the focus.
Reading
requestfocus
does not currently return any useful information.
| | requestfocusenabled |
An
int
that is
1
(the default)
when actions, like mouse clicks or changes to the
requestfocus
field, can steal the keyboard focus and
0
when they can not.
Note that this field does not affect acceptance of the keyboard focus
during normal focus traversal.
Reading returns the current state.
Writing immediately sets the filechooser's state to the new value.
| | root |
An
Object
that is automatically updated by the interpreter's layout machinery
so it is always the top-level object that contains the filechooser.
For example, put a filechooser in a panel and
root
will be set to that panel;
add the panel to a frame and the filechooser's
root
field will be set to that frame.
A filechooser's event handlers can use
root
when they need to interact with the other components in the container.
| | showing |
A read-only
int
that is non-zero when the filechooser is showing on the screen.
| | size |
A
Dimension
that determines the size of the filechooser
in units of 72 dots per inch.
Reading returns a snapshot of the current size.
Writing is allowed, but layout managers usually get the final say, so setting
size
should be viewed as a request that may not be honored.
| | tag |
A
String
used to identify the filechooser that is either supplied when
the filechooser is declared, or automatically generated otherwise.
Add a filechooser to a container, like a
JFrame
or
JPanel,
and the interpreter's layout machinery updates the
root
field so it points at the top-level container and then adds the filechooser, as
tag,
to the
root.components
dictionary.
| | tooltiptext |
A
String
of characters that is displayed in a tightly sized pop-up window that
appears near the cursor whenever the cursor lingers over the filechooser.
Setting this value to
NULL
(the default)
disables the tooltip mechanism.
Reading returns the current tooltip text.
Writing immediately sets the new tooltip text.
| | toyoixpath |
An
int
that controls what happens to platform dependent file separators when the
file
and
directory
fields are read.
When
toyoixpath
is non-zero all file separators are replaced by the slash character
/,
otherwise no changes are made.
| | transferhandler |
An
Object
that should be a
TransferHandler
or
String
that determines how the filechooser handles data transfer operations
like drag and drop.
A value that is a
String
but not
""
means the field named by the
String
should be used as the source and sink of the data that is transferred by
the filechooser.
The result is the same as assigning the
String
to the
property
field in a
TransferHandler
and then assigning that
TransferHandler
to
transferhandler.
The empty
String
""
is special and refers to the
TransferHandler
that Swing uses for automatic drag handling, if there is one.
Swing components that provide automatic drag handling start out with a
transferhandler
field that is not
NULL,
but the automatic drag handling is not enabled until
1
is stored in
dragenabled.
Swing components that provide their own drag and drop event handlers
currently must store
NULL
in
transferhandler
before those event handlers will start working.
| | visible |
An
int
that is
1
when the filechooser is visible, and
0
otherwise.
Reading returns the current visibility.
Writing immediately sets the filechooser's visibility to the new state.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
A filechooser can be told where to look by setting its
directory
or
file
fields.
When a filechooser is dismissed all you do is read the
file
field and you get the full pathname of the selected file, or
NULL
if no file was selected or the Cancel button was hit;
the style of that pathname is controlled by the
toyoixpath
field.
Event handlers are functions that must be added to a filechooser when it is
declared.
The handlers that work with filechooser are listed below;
the names should be familiar if you have done some Java programming.
The
itemStateChanged
event handler is only for menus.
| |
| Event Handlers: |
actionPerformed,
componentHidden,
componentMoved,
componentResized,
componentShown,
dragDropEnd,
dragEnter,
dragExit,
dragGestureRecognized,
dragMouseMoved,
dragOver,
drop,
dropActionChanged,
focusGained,
focusLost,
invocationRun,
itemStateChanged,
keyPressed,
keyReleased,
keyTyped,
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased,
mouseWheelMoved
| | |
| Example: |
The program,
import yoix.*.*;
JDialog browser = {
Dimension size = NULL;
String title = "File Browser Example";
int initialized = FALSE;
int modal = TRUE;
Array layout = {
new JFileChooser {
String tag = "$_chooser";
int mode = LOAD;
actionPerformed(e) {
root.SetVisible(FALSE);
}
},
};
SelectedFile() {
return(components.$_chooser.file);
}
SetVisible(int state) {
Point location;
if (!initialized) {
initialized = TRUE;
location.x = (VM.screen.width - this.size.width)/2;
location.y = (VM.screen.height - this.size.height)/2 - 72.0;
this.location = location;
}
this.visible = state;
}
};
browser.SetVisible(TRUE);
printf("The file you selected is: %s\n", browser.SelectedFile());
shows how to use a
JFileChooser
to build a screen that behaves pretty much like a
JFileDialog.
| | |
| See Also: |
BevelBorder,
Border,
EmptyBorder,
EtchedBorder,
invokeLater,
JButton,
JCanvas,
JCheckBox,
JCheckBoxMenuItem,
JChoice,
JColorChooser,
JComboBox,
JDesktopPane,
JDialog,
JFileDialog,
JFrame,
JInternalFrame,
JLabel,
JLayeredPane,
JList,
JMenu,
JMenuBar,
JMenuItem,
JPanel,
JPasswordField,
JPopupMenu,
JProgressBar,
JRadioButton,
JRadioButtonMenuItem,
JScrollBar,
JScrollPane,
JSeparator,
JSlider,
JSplitPane,
JTabbedPane,
JTable,
JTextArea,
JTextCanvas,
JTextField,
JTextPane,
JTextTerm,
JToggleButton,
JToolBar,
JTree,
JWindow,
LineBorder,
MatteBorder,
postEvent,
SoftBevelBorder,
TransferHandler
|
|