0

I use this statement to assign a scrollPane to a Jtable. However when I add the scrollPane to any other JPanel. The height of the scrollPane is much larger than the table height.

JPanel tablepane=new JPanel();
tableau= new JTable();
tableau.setModel(model);
tableC=new JScrollPane();
tableC.setViewportView(tableau);

https://i.stack.imgur.com/CAdZB.png

camickr
  • 321,443
  • 19
  • 166
  • 288
Saad
  • 23
  • 7
  • Possible duplicate of [Shrink JScroll Pane to same Height as JTable](https://stackoverflow.com/questions/6523974/shrink-jscroll-pane-to-same-height-as-jtable) – TheFlyBiker 420 Dec 04 '18 at 16:15

1 Answers1

0

If you want it the exact size then you can use:

table.setPreferredScrollableViewportSize(table.getPreferredSize());

after you load the data into the table.

camickr
  • 321,443
  • 19
  • 166
  • 288