public class FileComboBoxBrowser extends AbstractComboBoxBrowser<String>
AbstractComboBoxBrowser
to complete relative and
absolute path names of files and directories.
This class uses a FileSystemView
in order to create file objects
for auto completion.
To use it, use something like this:
JComboBox box = new JComboBox(); new FileComboBoxBrowser(box); box.setEditable(true);
Constructor and Description |
---|
FileComboBoxBrowser()
Constructs a new file combo box auto completion browser.
|
FileComboBoxBrowser(JComboBox<String> comboBox)
Creates a new combo box auto completion browser.
|
Modifier and Type | Method and Description |
---|---|
File |
getDirectory()
Returns the directory which is used for autocompleting relative path
names.
|
FileSystemView |
getFileSystemView()
Returns the file system view.
|
void |
setDirectory(File dir)
Sets the directory which is used for autocompleting relative path names.
|
void |
setFileSystemView(FileSystemView fsv)
Sets the file system view.
|
protected boolean |
update(String initials)
Interpretes the specified
initials as the initial
characters of an absolute or relative path name of a node in the file
system and updates the contents of the combo box model with possible
completions. |
getComboBox, setComboBox
public FileComboBoxBrowser()
AbstractComboBoxBrowser.setComboBox(javax.swing.JComboBox<E>)
must be called in order to use this object.public FileComboBoxBrowser(@CheckForNull JComboBox<String> comboBox)
comboBox
- The combo box to enable browsing for auto completions.
May be null
.public File getDirectory()
null
, then a call to this method reinitializes it by calling
FileSystemView.getDefaultDirectory()
on the
file system view.public FileSystemView getFileSystemView()
null
, then a call to this method reinitializes it by calling
FileSystemView.getFileSystemView()
.public void setDirectory(@CheckForNull File dir)
public void setFileSystemView(@CheckForNull FileSystemView fsv)
protected boolean update(String initials)
initials
as the initial
characters of an absolute or relative path name of a node in the file
system and updates the contents of the combo box model with possible
completions.
The elements in the combo box model are sorted according to their
natural comparison order.update
in class AbstractComboBoxBrowser<String>
initials
- The initial characters of a file or directory path name.true
if and only if the file system contains a
node with initials
as its initial characters and
hence the popup window with the completions should be shown.NullPointerException
- If the comboBox
property is
null
.Copyright © 2012–2014 Schlichtherle IT Services. All rights reserved.