Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can `JTableHeader` span over multiple columns?

I've spent quite some time searching for this and I've only found the GroupableHeader code. I need one header over 2 columns in a 2 column JTable. How can this be done without the use of the infamous GroupableHeader, while keeping the default look and feel of the `JTableHeader?


This is a graphical representations of what I have in mind:

_________________________
|     Table Header      |
|-----------------------|
|           |           |
|-----------|-----------|
|           |           |
|-----------|-----------|
like image 955
Igor Avatar asked Nov 02 '12 19:11

Igor


1 Answers

This depends on what eaxctly you want to achieve.

I did something similar by creating my own JTableHeader, which was essentially just a JPanel.

On it I placed "group" headers on the top row, over the columns I wanted to "group".

Then I cheated and used the existing tables row header and added it to the second row below the header.

This requires some slight of hand, as you need to know the columns you want to group/span and their widths. You also need to monitor for changes in their widths and update the header appropriately.

Most of the implementations I've seen use their own UI implementation, personally I don't like this as it undoes the work of the look and feel you're using.

You could have a look at this which demonstrates a number of interesting things you can do with JTables as well multi-column spanning, but again, it's using it's own UI to get it to work.

The implementation we've begin using at work works in the same way and the problem I have with it is that you can see the mouse resize cursor within the group header, which, to me, isn't really what you want the user to see

like image 54
MadProgrammer Avatar answered Oct 11 '22 17:10

MadProgrammer