Chapter 16. Advanced Table Examples
In this chapter, we’re going to take a different approach.
Tables are extremely flexible, useful gadgets. Here, we’re going to show
you how to put tables to work in more advanced situations. Most of these
examples require working on the TableModel itself or the TableColumnModel. But once you know what you’re
doing, subclassing these models is fairly easy and gives you a lot of
flexibility.
We will look at four examples:
A scrollable table with row headers. Remember that a
JTableunderstands column headers but doesn’t have any concept of a row header. Also, remember that aJScrollPaneunderstands both column and row headers. In this example, we’ll show you how to add row headers to aJTableand make them work properly within aJScrollPane.A table that has an extremely large number of rows. Scrolling stops working well when you have more than a few hundred rows. We’ll build a table with 10,000 rows, let you page up and down to select a range of 100 rows within the table, and then scroll back and forth within that more limited range.
A table with a custom editor and renderer for working with cells that contain something other than just text. We’ll represent a numeric value with a slider. The user can also move the slider to edit the value.
A
TableChartcomponent that builds pie charts based on theTableModelclass used byJTable. In this example, theJTableis almost superfluous, although it provides a convenient way to edit the data in the pie chart. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access