6.3.4. Listening to Tree Events

Most commonly, a tree component is paired with some other component. When the user selects tree nodes, some information shows up in another window. See Figure 6.33 for an example. When the user selects a class, the instance and static variables of that class are displayed in the text area to the right.


Figure 6.33. A class browser

To obtain this behavior, you need to install a tree selection listener. The listener must implement the TreeSelectionListener interface—an interface with a single method:

void valueChanged(TreeSelectionEvent event)

That method is called whenever the user selects or deselects tree nodes. ...

Get Core Java® Volume II—Advanced Features, Ninth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.