Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
More action with Struts 2
In a recent review of Struts 2 in Action, JW Blogger Oleg Mikheev notes that Struts 2 is "just a collection of extensions built upon WebWork, which is ultimately
the right thing to learn before starting a Struts 2 project." While Struts 2 has some architectural flaws, Oleg calls WebWork
well-designed, well-tested, and reliable. What are your experiences using Struts 2 and WebWork?
Also see "Hello World the WebWork way," a JavaWorld excerpt from WebWork in Action, by Patrick Lightbody and Jason Carreira.
| Memory Analysis in Eclipse |
| Enterprise AJAX - Transcend the Hype |
JFileChooser component that makes it easy to visually navigate the filesystem and select a file or directory from a list. Traditionally, users select a file in the file chooser's dialog by scrolling the chooser's list with a mouse and double-clicking the desired file. That method is fine for directories with a small number of files, but it becomes cumbersome and time-consuming when you're dealing with large directories with hundreds of files.
This article demonstrates how to implement an alternative way of choosing files by typing the first few characters of a filename. Once the selection bar is on the desired name, the user presses the Enter key to choose it. The type-ahead feature is implemented for files only, but you can easily extend it to include subdirectories as well.
The JFileChooser is a compound component, consisting of a number of child components. Those child components are standard Swing components,
such as JButton, JPanel, JComboBox, JList, and others. JFileChooser has only one JList component, which is wrapped in a scroll pane, and used to display subdirectories and files in the current directory (as shown
in Figure 1). I've highlighted that component with a red border.

Figure 1. JList descendent component in JFileChooser
To implement the type-ahead feature in JFileChooser, the utility must know the user's keystrokes. You could do that by registering the utility as a key listener on the list.
Unfortunately, the list is declared private, so the utility does not have direct access to it. You can, however, obtain a
reference to the list: the getComponents() method of the Container class returns all components added to a specified container, including those declared private.
Now you can easily go through a list of all JFileChooser's descendant components to find the only JList component. A recursive method seems the most natural in this situation:
private Component findJList(Component comp) {
if (comp.getClass() == JList.class) return comp;
if (comp instanceof Container) {
Component[] components = ((Container)comp).getComponents();
for(int i = 0; i < components.length; i++) {
Component child = findJList(components[i]);
if (child != null) return child;
}
}
return null;
}
Initially the findJList() method is passed a JFileChooser object, which itself is a container. The method retrieves all child components of that container by means of the getComponents() method, and recursively calls itself until a descendent component is found, which is an instance of JList. If the method is passed a component that is neither an instance of JList nor a container, it returns a null value to indicate that recursion process should continue. Once a JList component is found, findJList() exits from the for loop returning that component, which ends recursion calls.
Now the utility has a reference to the list component and can register as a key listener on it. The utility is interested
in just one particular key event, namely when the key is typed. Therefore, the utility class extends the KeyAdapter class and implements the keyTyped() method only: