How can I fill the height of a JScrollPane with empty JTable strings?

I put the JTable in a JScrollPane, but the table only contains a few rows, which makes the rest of the space empty.

Is there any way to make JTable fill the entire panel? let's say put blank lines so that the panel is full.

thanks

+6
source share
3 answers
table.setFillsViewportHeight( true ); 
+10
source

The JTable method JTable setPreferredScrollableViewportSize() is another way to manage screen real estate. Here is an example here .

+3
source

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.

+1
source

Source: https://habr.com/ru/post/888076/


All Articles