Can `JTableHeader` span over multiple columns?
Asked Answered
T

1

6

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      |
|-----------------------|
|           |           |
|-----------|-----------|
|           |           |
|-----------|-----------|
Turnaround answered 2/11, 2012 at 19:10 Comment(4)
This might help you: https://mcmap.net/q/1795660/-jtable-column-spanningGarton
@DanIliescu It's about how to span columns. I need to span only the header.Turnaround
JTableHeader has Borders, you can to put there own BordersMarshmallow
[This][1] is one way of doing what I need. All credit to MadProgrammer. [1]: #13214338Turnaround
O
3

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

Overdress answered 2/11, 2012 at 20:28 Comment(3)
Your answer about the Label header solves this one aswell. Thanks.Turnaround
the link is downBenevolent
@Benevolent This is a enhanced versionOverdress

© 2022 - 2024 — McMap. All rights reserved.