• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Nested JTables - The header of the inner JTable is not showing

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to make a nested JTable however, for some reason the header of the inner table is not showing for some reason, I have spent some days trying to find a solution without finding one. I basically have no idea what's wong. And for some reason I cant find any topics about nested JTables when googling.

I'd be grateful if someone could help me with this.

Thanks in advance for any help.


SSCCE of my code.


 
Rancher
Posts: 3068
24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The header appears automatically when you add the table to a scroll pane and then add the scrollpane to the GUI.

Otherwise you need to create a panel with a border layout and add the header to the NORTH and the table to the CENTER.
 
Alexander Walker
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Camick wrote:Otherwise you need to create a panel with a border layout and add the header to the NORTH and the table to the CENTER.



Do you mean that I need to do this inorder to do a nested table? And The first option won't work in an inner table? I mean adding the table to a scrollpane won't work on an inner table?
 
Rob Camick
Rancher
Posts: 3068
24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Alexander Walker
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Camick wrote:



Thanks that worked fine.

Is there anyway to make the nested table so that the user can interact with it like with a normal table. For example changing the size of a header column by draging the border between the column on the header. Or draging the scrollbar on the side, if the column height is too small to show every row in the table.

I Hope that made sense.
 
Sheriff
Posts: 21783
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TableCellRenderers are only used for painting. For user interaction you'll need a TableCellEditor instead.
 
Alexander Walker
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it to work now.

Thanks for all the help I have got.

By the way, is there anyway to get around that you have to first click the outer table column with a table in it once before you can edit the inner table?
I hope it made sense.

I guess this would be impossible though? Since the reason you have to click an extra time is because you have to enter edit mode in the outer table, inorder to start editing the inner table, but I thought I would ask anyway. But if someone knows of a way, then I 'd like to know it too.
 
Alexander Walker
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was'nt exactly impossible, and it was'nt that hard to do either once I started thinking a bit about it. In my solution I just added a MouseMotionListener to my outer table, that programatically entered edit mode when the mouse was above a cell in column 0 or 1, since they contained the nested table.

Here is my solution for those who want it.

 
please buy my thing and then I'll have more money:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!