Dimension (@NotNull JList<?> list) { if (JList.class != getPreferredScrollableViewportSizeDeclaringClass(list)) { return list.getPreferredScrollableViewportSize(); // may be null } Dimension size = getPreferredSizeWithoutScrollBars(list); if (JList.VERTICAL != list.getLayoutOrientation()) return size; ListModel<?> model = list.getModel(); int modelRows = model == null ? 0 : model.getSize(); int visibleRows = list.getVisibleRowCount(); boolean forceVisibleRowCount = Boolean.TRUE.equals(ClientProperty.get(list, FORCE_VISIBLE_ROW_COUNT_KEY)); if (!forceVisibleRowCount && visibleRows > 0) { visibleRows = Math.min(modelRows, visibleRows); } if (visibleRows <= 0) { visibleRows = Registry.intValue("ide.preferred.scrollable.viewport.visible.rows", 10); } boolean addExtraSpace = Registry.is("ide.preferred.scrollable.viewport.extra.space", true); Insets insets = getInnerInsets(list); size.height = insets != null ? insets.top + insets.bottom : 0; if (modelRows == 0) { int fixedWidth = list.getFixedCellWidth(); int fixedHeight = list.getFixedCellHeight(); if (fixedWidth <= 0) { fixedWidth = Registry.intValue("ide.preferred.scrollable.viewport.fixed.width", 256); } if (fixedWidth <= 0) { fixedWidth = JBUIScale.scale(256); // scaled value from JDK } if (fixedHeight <= 0) { fixedHeight = Registry.intValue("ide.preferred.scrollable.viewport.fixed.height", 0); } if (fixedHeight <= 0) { fixedHeight = UIManager.getInt("List.rowHeight"); } if (fixedHeight <= 0) { fixedHeight = JBUIScale.scale(16); // scaled value from JDK } size.width = insets != null ? insets.left + insets.right + fixedWidth : fixedWidth; size.height += fixedHeight * visibleRows; if (addExtraSpace) size.height += fixedHeight / 2; } else if (visibleRows > 0) { int lastRow = Math.min(visibleRows, modelRows) - 1; Rectangle bounds = list.getCellBounds(lastRow, lastRow); if (bounds == null) return size; // null UI? size.height = bounds.y + bounds.height; if (insets != null) size.height += insets.bottom; if (modelRows < visibleRows) { size.height += (visibleRows - modelRows) * bounds.height; } else if (modelRows > visibleRows) { if (addExtraSpace) size.height += bounds.height / 2; } } return size; }