@Override public int getRowHeight() { if (myRowHeightIsComputing) { return super.getRowHeight(); } if (myRowHeight < 0) { try { myRowHeightIsComputing = true; for (int row = 0; row < getRowCount(); row++) { for (int column = 0; column < getColumnCount(); column++) { final TableCellRenderer renderer = getCellRenderer(row, column); if (renderer != null) { final Object value = getValueAt(row, column); final Component component = renderer.getTableCellRendererComponent(this, value, true, true, row, column); if (component != null) { final Dimension size = component.getPreferredSize(); myRowHeight = Math.max(size.height, myRowHeight); } } } } } finally { myRowHeightIsComputing = false; } } if (myMinRowHeight == null) { myMinRowHeight = getFontMetrics(UIManager.getFont("Label.font")).getHeight(); } return Math.max(myRowHeight, myMinRowHeight); }
private int computeHeight() { FontMetrics fm = myRootPane.getFontMetrics(getFont()); int fontHeight = fm.getHeight(); fontHeight += 7; int iconHeight = 0; if (getWindowDecorationStyle() == JRootPane.FRAME) { iconHeight = IMAGE_HEIGHT; } return Math.max(Math.max(fontHeight, iconHeight), JBUI.scale(myIdeMenu == null ? 28 : 36)); }
public void updateColumnSizes() { final JTableHeader header = getTableHeader(); final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer(); final RowSorter<? extends TableModel> sorter = getRowSorter(); final List<? extends RowSorter.SortKey> current = sorter == null ? null : sorter.getSortKeys(); ColumnInfo[] columns = getListTableModel().getColumnInfos(); for (int i = 0; i < columns.length; i++) { final ColumnInfo columnInfo = columns[i]; final TableColumn column = getColumnModel().getColumn(i); // hack to get sort arrow included into the renderer component if (sorter != null && columnInfo.isSortable()) { sorter.setSortKeys( Collections.singletonList(new RowSorter.SortKey(i, SortOrder.ASCENDING))); } final Component headerComponent = defaultRenderer == null ? null : defaultRenderer.getTableCellRendererComponent( this, column.getHeaderValue(), false, false, 0, 0); if (sorter != null && columnInfo.isSortable()) { sorter.setSortKeys(current); } final Dimension headerSize = headerComponent == null ? new Dimension(0, 0) : headerComponent.getPreferredSize(); final String maxStringValue; final String preferredValue; if (columnInfo.getWidth(this) > 0) { int width = columnInfo.getWidth(this); column.setMaxWidth(width); column.setPreferredWidth(width); column.setMinWidth(width); } else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) { int width = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth(); width = Math.max(width, headerSize.width); column.setPreferredWidth(width); column.setMaxWidth(width); } else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) { int width = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth(); width = Math.max(width, headerSize.width); column.setPreferredWidth(width); } } }
@Override public Dimension preferredLayoutSize(final Container parent) { Dimension result = new Dimension(); for (int i = 0; i < parent.getComponentCount(); i++) { final Dimension prefSize = parent.getComponent(i).getPreferredSize(); result.width += prefSize.width; result.height = Math.max(prefSize.height, result.height); } return result; }
public void setMinRowHeight(int i) { setRowHeight(Math.max(i, getRowHeight())); }
public void updateColumnSizes() { final JTableHeader header = getTableHeader(); final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer(); final RowSorter<? extends TableModel> sorter = getRowSorter(); final List<? extends RowSorter.SortKey> current = sorter == null ? null : sorter.getSortKeys(); ColumnInfo[] columns = getListTableModel().getColumnInfos(); int[] sizeMode = new int[columns.length]; int[] headers = new int[columns.length]; int[] widths = new int[columns.length]; int allColumnWidth = 0; int varCount = 0; // calculate for (int i = 0; i < columns.length; i++) { final ColumnInfo columnInfo = columns[i]; final TableColumn column = getColumnModel().getColumn(i); // hack to get sort arrow included into the renderer component if (sorter != null && columnInfo.isSortable()) { sorter.setSortKeys( Collections.singletonList(new RowSorter.SortKey(i, SortOrder.ASCENDING))); } final Component headerComponent = defaultRenderer == null ? null : defaultRenderer.getTableCellRendererComponent( this, column.getHeaderValue(), false, false, 0, 0); if (sorter != null && columnInfo.isSortable()) { sorter.setSortKeys(current); } if (headerComponent != null) { headers[i] = headerComponent.getPreferredSize().width; } final String maxStringValue; final String preferredValue; if (columnInfo.getWidth(this) > 0) { sizeMode[i] = 1; int width = columnInfo.getWidth(this); widths[i] = width; } else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) { sizeMode[i] = 2; widths[i] = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth(); varCount++; } else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) { sizeMode[i] = 3; widths[i] = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth(); varCount++; } allColumnWidth += widths[i]; } // apply: distribute available space between resizable columns // and make sure that header will fit as well int viewWidth = getParent() != null ? getParent().getWidth() : getWidth(); double gold = 0.5 * (3 - Math.sqrt(5)); int addendum = varCount == 0 || viewWidth < allColumnWidth ? 0 : (int) ((allColumnWidth < gold * viewWidth ? gold * viewWidth : allColumnWidth < (1 - gold) * viewWidth ? (1 - gold) * viewWidth : viewWidth) - allColumnWidth) / varCount; for (int i = 0; i < columns.length; i++) { TableColumn column = getColumnModel().getColumn(i); int width = widths[i]; if (sizeMode[i] == 1) { column.setMaxWidth(width); column.setPreferredWidth(width); column.setMinWidth(width); } else if (sizeMode[i] == 2) { width = Math.max(width + addendum, headers[i]); column.setPreferredWidth(width); column.setMaxWidth(width); } else if (sizeMode[i] == 3) { width = Math.max(width + addendum, headers[i]); column.setPreferredWidth(width); } } }
public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); return new Dimension(Math.max(IMAGE_WIDTH, size.width), Math.max(size.height, IMAGE_HEIGHT)); }