Here you can find the source of setVisibleRowCount(final JTable table, final int rows)
Parameter | Description |
---|---|
table | the table |
rows | number of rows to have visible without scrolling |
public static void setVisibleRowCount(final JTable table, final int rows)
//package com.java2s; import java.awt.Dimension; import javax.swing.JTable; public class Main { /**/*w ww.j av a 2 s . c om*/ * Set the preferred viewport size on a table based upon the number of rows * that should be visible and the current heights of the rows. Based upon code * from http://www.javalobby.org/java/forums/t19559.html * * @param table the table * @param rows number of rows to have visible without scrolling */ public static void setVisibleRowCount(final JTable table, final int rows) { int height = 0; for (int row = 0; row < rows; row++) { height += table.getRowHeight(row); } table.setPreferredScrollableViewportSize( new Dimension(table.getPreferredScrollableViewportSize().width, height)); } }