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?
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
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
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.
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!