A bit more complete solution: JBroTable.
It's based on MadProgrammer's answer. It restricts column dragging out of the group too. And brings some extra features:
- Arbitrary number of rows
- Natural API for model creation
- Generic support for other L&Fs (Windows system L&F, GTK, Nimbus etc.)
Sample model creation:
IModelFieldGroup groups[] = new IModelFieldGroup[] {
new ModelFieldGroup( "A", "A" )
.withChild( new ModelField( "B", "B" ) )
.withChild( new ModelField( "C", "C" ).withRowspan( 2 ) ), // Custom rowspan set.
new ModelFieldGroup( "D", "D" )
.withChild( new ModelField( "E", "E" ) )
.withChild( new ModelField( "F", "F" ) ),
new ModelField( "G", "G" ),
new ModelFieldGroup( "H", "H" )
.withChild( new ModelFieldGroup( "I", "I" )
.withChild( new ModelField( "J", "J" ) ) )
.withChild( new ModelField( "K", "K" ) )
.withChild( new ModelFieldGroup( "L", "L" )
.withChild( new ModelField( "M", "M" ) )
.withChild( new ModelField( "N", "N" ) ) )
};
Result:
Animated demo (2.5M)
Update:
Added drawing of the whole dragged columns group.
GroupableHeader
redefines the look and feel delegate used to paint the column header. If you want to provide this functionality, you are going to have to (heavily) modify the code to introduce the support to it... – Lohman