diff --git a/platform/platform-api/src/com/intellij/ui/table/JBTable.java b/platform/platform-api/src/com/intellij/ui/table/JBTable.java index 9e6a7cfb1444..bda0fef97963 100644 --- a/platform/platform-api/src/com/intellij/ui/table/JBTable.java +++ b/platform/platform-api/src/com/intellij/ui/table/JBTable.java @@ -59,6 +59,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component private AsyncProcessIcon myBusyIcon; private boolean myBusy; + private int myMaxItemsForSizeCalculation = Integer.MAX_VALUE; public JBTable() { this(new DefaultTableModel()); @@ -153,8 +154,8 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component if (myRowHeight < 0) { try { myRowHeightIsComputing = true; - for (int row = 0; row < getRowCount(); row++) { - for (int column = 0; column < getColumnCount(); column++) { + for (int row = 0; row < Math.min(getRowCount(), myMaxItemsForSizeCalculation); row++) { + for (int column = 0; column < Math.min(getColumnCount(), myMaxItemsForSizeCalculation); column++) { final TableCellRenderer renderer = getCellRenderer(row, column); if (renderer != null) { final Object value = getValueAt(row, column); @@ -818,4 +819,15 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component return resizingAllowed && columnModel.getColumn(columnIdx).getResizable(); } } + + /** + * JTable gets table data from model lazily - only for a table part to be shown. + * JBTable loads all the data on initialization to calculate cell size. + * This methods provides possibility to calculate size without loading all the table data. + * + * @param maxItemsForSizeCalculation maximum number ot items in table to be loaded for size calculation + */ + public void setMaxItemsForSizeCalculation(int maxItemsForSizeCalculation) { + myMaxItemsForSizeCalculation = maxItemsForSizeCalculation; + } }