15.1. Using Custom Data Models and Renderers

With almost any Swing component, you can separate the underlying data structure from the GUI control that renders and displays the data. Often you can use an array to hold the data, as is the case with lists, trees, and tables. As a convenience, Swing lets you define and use your own data structures directly in these advanced GUI controls. You simply need to implement an interface that tells the Swing component how to access and display the data. The advantage here is that you don't have to copy the data into the control, but simply tell the GUI control how to access it.

Swing has a few simple defaults for displaying values in a JList, JTree, and JTable. For example, in a JList, values that are String ...

Get Core Web Programming, Second Edition 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.