title: JTable height calculation
body: <p><strong>Solution</strong></p>
  
  <p>jtable.getHeight does not include header element</p>
  
  <p>jtable.getRowHeight include margin</p>
  
  <p>and the example has 15px actual height, not 14px</p>
  
  <p><strong>More clear example</strong></p>
  
  <pre><code>RO 16
  R1 16
  R2 16
  HEIGHT 48
  INTERCELL java.awt.Dimension[width=1,height=1]
  MARGIN 1
  </code></pre>
  
  <p>I have JTable with 3 rows. Each row is <strong>16px</strong>. And each row margin 1px.
  So I suspect that table height should be 16 + 1 + 16 + 1 + 16 = 50px</p>
  
  <p>BUT getHeight returns 48px</p>
  
  <p>Also I did streenshot. Each row has <strong>14px</strong> height actually.</p>
  
  <p>How how is it possible????</p>
  
  <p><a href="https://raw.githubusercontent.com/ezh/DOTFILES/master/PUBLIC/SO-34135994/TableExample.java" rel="nofollow noreferrer">Source code</a></p>
  
  <p><a href="https://i.stack.imgur.com/esL0K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/esL0K.png" alt="Visual representation"></a></p>
  
  <pre><code>    //headers for the table
      String[] columns = new String[] {
          "Id", "Name", "Hourly Rate", "Part Time"
      };
  
      //actual data for the table in a 2d array
      Object[][] data = new Object[][] {
          {1, "John", 40.0, false },
          {2, "Rambo", 70.0, false },
          {3, "Zorro", 60.0, true },
      };
  
      //create table with data
      JTable table = new JTable(data, columns);
  
      //add the table to the frame
      this.add(table);
  
      this.setTitle("Table Example");
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
      this.pack();
      this.setVisible(true);
      System.out.println("RO " + table.getRowHeight(0));
      System.out.println("R1 " + table.getRowHeight(1));
      System.out.println("R2 " + table.getRowHeight(2));
      System.out.println("HEIGHT " + table.getHeight());
      System.out.println("INTERCELL " + table.getIntercellSpacing());
      System.out.println("MARGIN " + table.getRowMargin());
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Original question</strong></p>
  
  <p>I have simple test frame with jtable in the scroll pane.</p>
  
  <p>The table minimum height is less than actual height.
  header + rows &lt; actual size</p>
  
  <p>It is nonsense.</p>
  
  <pre><code>  val jtable = view.tableControl
    val headerHeight = jtable.getTableHeader.getHeight
    val rowsHeight = (0 until jtable.getRowCount()).foldLeft(0) { (heightAccumulator, counter) ⇒
      println("Row " + counter + " height " + jtable.getRowHeight(counter))
      jtable.getRowHeight(counter) + heightAccumulator
    }
    val rowsMargin = jtable.getRowMargin() * (jtable.getRowCount() - 1)
    println("Actual height " + jtable.getHeight())
    println("Header height " + headerHeight)
    println("Margin height " + jtable.getRowMargin())
    println("PreferredScrollableViewportSize" + jtable.getPreferredScrollableViewportSize())
    println("Rows height " + rowsHeight)
    println("Should be at least: " + (rowsHeight + headerHeight + rowsMargin))
  </code></pre>
  
  <p>and I got</p>
  
  <pre><code>Row 0 height 16
  Row 1 height 16
  Row 2 height 16
  Row 3 height 16
  Row 4 height 16
  Actual height 80
  Header height 19
  Margin height 1
  PreferredScrollableViewportSizejava.awt.Dimension[width=450,height=400]
  Rows height 80
  Should be at least: 103
  </code></pre>
  
  <p>The JTable lays inside the frame without any scroll bars. It is fully visible and there is a lot of space bellow.</p>
  
  <p>How? How <code>jtable.getHeight()</code> of fully visible table may returns height less then (rows * rowHeight + header)?</p>