• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable invisible headers

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, well, I was reading on Jtables yesterday, and they will get scrolled out of view regardless. Sorry
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic