I'm not sure if this is the best way, but it should work fine:
int rows = jTable1.getRowCount(); int rowHeight = jTable1.getRowHeight(); int tableHeight = jTable1.getTableHeader().getHeight()+(rows*rowHeight); System.out.println("JScrollpane: "+jScrollPane1.getViewport().getHeight()); while( tableHeight<jScrollPane1.getViewport().getHeight()){ System.out.println("JTable: "+tableHeight); ((DefaultTableModel) jTable1.getModel()).addRow(new Object[]{null,null,null,null}); tableHeight+=rowHeight; }
Obviously, you will need to change the model and the inserted data to whatever you use.
source share