Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable invisible headers  RSS feed

 
Nathanael Ulrick
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I've got a JTable placed like so:
JFrame
->JSplitPane
-->JScrollPane
--->JPanel (BorderLayout)
---->JTable (CENTER)
(where -> indicates "inside")

The problem is that the table headers have disappeared, which looks pretty nice in fact, but it's not what I want.
The JPanel between the ScrollPane and JTable is essential as it's actually a class which extends JPanel and does some necessary stuff on the side. I've tried plenty of re-arranging of the above hierarchy, but something's always turned out wrong.
Given the above hierarchy, is there any way to make the headers appear?

Thanks
Nat
 
Nathanael Ulrick
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked around this by explicitly adding the JHeader to the JPanel as well.
Unfortunately the header doesn't stay in view during scrolling like it normally does.
Nat
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was wonder how did you get the table inside the frame amd panel. and my headers have disappeared also.
 
Swamy Vatti
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Headers for table will be displayed if the table is in a JScrollPane. So try adding another scrollpane(with the table) to the JPanel
 
Nathanael Ulrick
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that -- what I got was a ScrollPane which took up as much as one might expect it to take up in a BorderLayout.CENTER within a JPanel, unfortunately.
Originally posted by Swamy Vatti:
Headers for table will be displayed if the table is in a JScrollPane. So try adding another scrollpane(with the table) to the JPanel

 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I ended up doing:
objectTable = new JTable(tabledata, columnheaders);
objectTable.setPreferredScrollableViewportSize(new Dimension(600, 170));
TablescrollPane = new JScrollPane(objectTable);
getContentPane().add(TablescrollPane);
I don't know if it will help you.
 
Nathanael Ulrick
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I've got to sneak a JPanel in there somehow. It's just that I've got an abstract class which extends JPanel, and this abstract class does other essential stuff.
Otherwise your way would be the easiest and best way to do it, I think.
Not to worry though, I can get the headers to appear, which is most important -- nevermind if they get scrolled out of view.
Cheers!
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, well, I was reading on Jtables yesterday, and they will get scrolled out of view regardless. Sorry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!