Show Column Header on dragging column
Asked Answered
A

2

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?

Auxochrome answered 26/11, 2013 at 0:55 Comment(1)
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...Lohman
L
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

Lohman answered 26/11, 2013 at 5:10 Comment(10)
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??Auxochrome
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 issuesAuxochrome
this implementation depends to the look and feel??Auxochrome
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.Lohman
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.Lohman
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??Auxochrome
@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.Studley
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? (@Studley released theirs as public domain). Thanks!Valenzuela
@Valenzuela 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 messLohman
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 :-)Valenzuela
S
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.

Studley answered 19/7, 2015 at 0:15 Comment(1)
That's looking great @Qualtagh! Thanks for contributing!Valenzuela

© 2022 - 2024 — McMap. All rights reserved.