Java Reference
In-Depth Information
22.
{
23.
DefaultMutableTreeNode curNode =
24.
new DefaultMutableTreeNode(currentFile.getName());
25.
if (currentFile == startFile)
26.
{
27.
directoryTreeModel = new DefaultTreeModel(curNode);
28.
}
29.
if (currentFile.isDirectory())
30.
{
31.
File[] files = currentFile.listFiles();
32.
for ( int i=0;i<files.length; i++) {
33.
directoryTreeModel.insertNodeInto(recursion(files[i]),curNode,0);
34.
35.
}// for i
36.
}
37.
return (curNode);
38.
}
39. }
16.5
Combo boxes
Combo boxes are graphical components that combine text fields and lists. Like
lists, they offer a selection of items to choose from and, like text fields, the user
can type a text. Combo boxes are used if there is a predefined set of options that
cover most cases but not all. For example, if one wants to enter a date into an
electronic appointment book, the current year and the following two will do most
of the time. Only rarely are there dates further in the future. It is then convenient
to have a list with the current year and the following two to choose from. If the
date is at least three years ahead, then one can enter the year number.
16.5.1
Class JComboBox
A combo box looks like a text field with a small button attached at its right side.
The button shows an arrow pointing downwards. If the arrow is clicked, a list rolls
down out of the text field. Items can be selected from the list or text can be typed
into the text field. After selecting an item or hitting the return key the list is rolled
up again. Note that text written by the user is not permanently added to the list.
We describe some features of class JComboBox which implements combo boxes in
Swing and then present an application using this graphic component.
JComboBox()
JComboBox(String[] listEntries)
JComboBox(Vector[] listEntries)
additem(String listEntry)
Search WWH ::




Custom Search