What Next?

With all of this control over the look of a tree and its contents, you can create some impressive interfaces for a wide variety of data. You can create your own network management software that lets you browse domains and subdomains and computers and users. Any hierarchy of information you can think of can now be shown graphically.

It is worth pointing out, however, that you are not restricted to graphical applications with these models. You can use the DefaultTreeModel to store regular, hierarchical data, even if you have no intention of displaying the data on a screen. The model is flexible and provides a good starting point if you don’t have any tree data structures of your own lying around.

Get Java Swing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.