2

I am looking for a solution for a JTable where I can vary the number of columns in each row, but where the size (in pixels) of the row is constant.

I found stackoverflow referencing so far only dead-links to an old solution:

JTable with varying number of columns per row

Is there a newer better way to do it now ? If so, what? If not, does anyone know what the old solution was?

thanks.

Community
  • 1
  • 1
svaens
  • 649
  • 7
  • 23
  • 3
    spanning cells is not supported, all those old examples were/are hacks which require tweaking the internals of the ui-delegate - nothing trivial and lots of work. If you can afford it, you might be better off with a commercial solution like JIDE. Just sayin' :-) – kleopatra Jan 09 '13 at 16:48
  • I should note: I can only use java 6. If a new solution requires java7, i'm out of luck, and should stick with whatever the old solution was. – svaens Jan 09 '13 at 16:55
  • 1
    Although it is not appropriate, if you don't have too many rows in your table, you could consider using a `JPanel` with a `GridBagLayout` which supports col/row span (and many other stuffs) – Guillaume Polet Jan 09 '13 at 17:21

2 Answers2

1

I would create a renderer (panel with multiple fixed size labels or even multiple panels for each type of row).

It should be one column in TableModel with the renderer applied.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
1

Does anyone know what the old solution was?

The examples, which appear to have been created for a Swing beta release in the last millennium, may be found here. You may be looking for MultiSpanCellTable. They may be a useful object of study, but they are not current. YMMV.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045