Top.Mail.Ru
September 25th, 2008 - Java developers — LiveJournal
? ?

Java developers

September 25th, 2008
Image

08:12 pm - Imagesparkymark - Anatomy of a JTable

Can anyone please point me at a reference for what dimensions (inset, border, cell borders added by renderer) contribute to a JTable?

I am trying to make a pair of JLabels sit on top of a four-column JTable in their own BoxLayout panel, effectively looking the headers for two columns each (the real table header is disabled). Using ColumnModel.getWidth() gives me something close to the values to use as preferredSize on the JLabels, but my code is now littered with magic fudge factors to account for whatever difference there is between the sum of two getWidths and the distance from one side of a pair of columns to the other.

--------------------------
|   Label1    | Label2    |
--------------------------- 
|   c0 |  c1  |  c2  | c3 |
|      |      |      |    |    (Actually it is a little more complicated as there are five columns 
|      |      |      |    |     and I want to ignore the first column: I create a Box rigid-area
|      |      |      |    |     with width equal to the first TableColumn.getWidth and that looks wrong
                                by about three pixels.)

Any alternative approach welcome: I saw some code from 1998 (forget enhanced for-loops, this code looks to have predated java.util.Iterator and every collection is a Vector!) for nesting real table-headers, but I could not get that to work under Java 6. The table has no interactive element and I probably should have just not used a table at all and done it all with GridBaglayout and made every cell a tiny label.
Powered by LiveJournal.com
Image