Friday, March 4, 2011

Of JTables and ScrollPanes

While working on a Swing app today, I came across some interesting code where a class named RowHeader extended JTable.  WTF? In looking at it more closely, it seemed - aha! - they're creating a table to serve as the row header in the JScrollPane.  Makes sense - that way when the table is the viewport of the scroll pane, the column headers don't scroll with the table... just what you want.  I need to do that everywhere.
But wait - it already does that.  How do it know?  My tables don't do that, yet the scroll pane knows to put the row header outside the scroll view port.  Even the simple example here doesn't do anything special to accomplish this task.  I browsed through a bit of the source code to JScrollPane, it must be looking for a JTable instance, but I don't see where right off hand.
So I suspect this is relatively new functionality and the "legacy" code was doing the same thing before Swing did it automatically.

Now, to just get the sorting to show...

No comments: