title: Resize a Jtable Vertically based on it's content
body: <p>I have a view in my java project that needs to resize a table.
  I have <strong>n</strong> number of <strong>Jtables</strong> inside a <strong>JScrollPane</strong>. Some of them doesn't have enough rows to fill the total size of the table. The best solution I think would be to resize the table to fill to the number of rows that were allocated.
  <br></p>
  
  <p>1) The table has a dimension of 4x4 but if there is not enough rows (i.e, less than 4) it will have a gap, which I don't want. </p>
  
  <p>Since this table is static and won't be changed how can I resize this table programmatically based on the number of rows that it will have, like having 1, 2 or only 3 rows and not have this gap?</p>
  
  <p>PS: I know how many rows it will have, I just don't know how to resize the table height programmatically during runtime.</p>
  
  <p><a href="https://i.stack.imgur.com/VsIkG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VsIkG.png" alt="TableModel"></a></p>