1

i implement the code in GroupableHeader and try to enable the reordering allowed but i have two problems:

1: When dragging a column the header don´t see over the column
2: How restrict the dragged area of the column to prevent the column exit of the columnGroup

I don´t understand why the header don´t see on column dragging, i read the table header api but did not find any solution. Any ideas for solving these problems?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 3
    Welcome to the wonderful world of old code on the internet. Basically, the `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... – MadProgrammer Nov 26 '13 at 00:59

2 Answers2

10

My predecessor also thought that using code they copied off the internet was a good idea...fortunately for my company, I don't

I spent about 4 weeks of my spare time digging through the implementation and comparing it with the default BasicTableHeaderUI figuring out how to reinstate...

  • Column ordering, including, limiting the grouped columns to there group
  • Row sorting
  • Various other bits and pieces

This is a incomplete solution, as I've not yet quite got to the point where when you drag a group and have it show all the columns in the group, but that's within the TableUI

Draggable column groups

Unfortunately, I can't paste the code, it's over the 3000 character limit, but you can grab a copy from here

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Thank you very much! I merge your work with my own code and i think share it when have a good implementation,do you leave me share it to the comunity?? – user2958096 Nov 26 '13 at 14:48
  • And other cuestion, how set the look and feel?? I test on Windows and doesn´t work. I override the installUi and UninstallUi but the dragged present many issues – user2958096 Nov 26 '13 at 15:51
  • this implementation depends to the look and feel?? – user2958096 Nov 26 '13 at 17:19
  • It shouldn't. My main test class simply installed the system look and feel. I can't run it under Windows at the moment, but the last time I did, it seemed to work fine. – MadProgrammer Nov 26 '13 at 18:54
  • Remember, you're re-implementing a look and feel delegate, it "may" have some side effects. The API itself should be installing it's on UI delegate, it's self contained. – MadProgrammer Nov 26 '13 at 18:55
  • thanks, i change the look and feel to the java default and I saw the same problems, but i understand how to solve it. If i have free time, i´ll post the solution. Finally, i have a last question, if i wanted to implemented the column movement when you drag a group, i should change the jtable paint method?? – user2958096 Nov 27 '13 at 23:04
  • @MadProgrammer, thank you for showing the way how to do it! That's a great job. I took your code and spent 4 weeks more to create a library for JTable on steroids: it supports arbitrary number of header rows and other L&Fs. Take a look at my answer. – Qualtagh Jul 19 '15 at 00:19
  • Thank you both for your great contributions! Quick question @MadProgrammer, what license is your code released under and do you happen to have a public repo for it? (@Qualtagh released theirs as public domain). Thanks! – StephMW Nov 17 '15 at 09:16
  • @StephMW There is license attached to the code (I believe SO requires a open license anyway) and right now, no, I don't have a public repo. I'm in the process of cleaning it all up and moving the code over to maven, so it's all a mess – MadProgrammer Nov 17 '15 at 09:18
  • Ah! I must have missed it looking at the zip on dropbox. Happy to help test out your future maven uploads anytime, just give us a heads up :-) – StephMW Nov 17 '15 at 09:44
3

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:

Result

Animated demo (2.5M)

Update:

Added drawing of the whole dragged columns group.

Qualtagh
  • 721
  • 6
  • 15