• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hide some column headers on JTable  RSS feed

 
Alfonso Sanz
Ranch Hand
Posts: 69
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

i know is possible to hide the complete header locating a Jable out of JScrollpane.

My question is if is there any chance to hide only some column headers but not all or even combining them in just one colum (several but not all).

Thanks in advande.
 
Rob Camick
Ranch Foreman
Posts: 2821
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can remove a TableColumn from the TableColumnModel of the JTable:

 
Alfonso Sanz
Ranch Hand
Posts: 69
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Mr. Camick, but my idea is not to remove columns but only the header of some of my table columns instead

i have no idea if exists any method for doing or i need to implement my own headers by JFrames, that latter approach is not very accurate for me because I lose the capability of sorting.


Thanks again.
 
Paul Clapham
Sheriff
Posts: 22697
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to imagine what a JTable would look like if it had some table headers visible and some table headers "hidden". Would that be the same as just changing the "hidden" table headers' text to an empty string, or would there be some other visible differences?
 
Alfonso Sanz
Ranch Hand
Posts: 69
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Paul,

My current solution is working with headers with empty strings, but It does`t look very nice. My table is growing and shrinking dynamically and those empty headers doesn't look cool.

I have attached how it looks like,

I would like to implement one of thw solutions:

1) Combine all dynamically added headers in one
or
2) Hide/Remove the header fot those headers...

Thanks in advance.


Captura.PNG
[Thumbnail for Captura.PNG]
 
Paul Clapham
Sheriff
Posts: 22697
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... you don't like the borders around the empty column headers? I can't guess what about that picture looks uncool to you. Maybe you could explain a bit more?

And I'm not sure which of those headers are "dynamically added" and how they look different than the ones which are statically added.
 
Rob Camick
Ranch Foreman
Posts: 2821
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a link to some old code that might help:

http://www.java2s.com/Code/Java/Swing-Components/MultiSpanCellTableExample.htm
 
Paul Clapham
Sheriff
Posts: 22697
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I remembered something like that! Wow... 1998, that's definitely old code. But it should work, I think.
 
Rob Camick
Ranch Foreman
Posts: 2821
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's definitely old code. But it should work, I think


Definitely buyer beware and no refund if it doesn't work.

But at least it demonstrates that this is a non trivial question and the OP may want to find a different solution.

Maybe a solution is to remove the table header from the scrollpane and just add a JLabel with text to represent the header?
 
Alfonso Sanz
Ranch Hand
Posts: 69
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,

Iwill hice It a try!!

Thanks you again
 
Alfonso Sanz
Ranch Hand
Posts: 69
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again!

Tested it! but it combine cells instead of headers.

Anyway. Probably the best idea is to use JLabels as headers making them sensitives to allow sorting.


Thank you a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!