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 2f67b1bfefe8..342f8578e0e1 100644 --- a/platform/platform-api/src/com/intellij/ui/table/JBTable.java +++ b/platform/platform-api/src/com/intellij/ui/table/JBTable.java @@ -320,6 +320,17 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component } } + @Override + public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { + if (orientation == SwingConstants.VERTICAL) { + return super.getScrollableUnitIncrement(visibleRect, orientation, direction); + } + else { // if orientation == SwingConstants.HORIZONTAL + // use smooth editor-like scrolling + return SwingUtilities.computeStringWidth(getFontMetrics(getFont()), " "); + } + } + @Override public void doLayout() { super.doLayout(); diff --git a/platform/platform-api/src/com/intellij/ui/table/TableView.java b/platform/platform-api/src/com/intellij/ui/table/TableView.java index 06e05fc8e15d..e9a1c7e5fa26 100644 --- a/platform/platform-api/src/com/intellij/ui/table/TableView.java +++ b/platform/platform-api/src/com/intellij/ui/table/TableView.java @@ -93,8 +93,7 @@ public class TableView extends BaseTableView implements ItemsProvider, Sel int[] sizeMode = new int[columns.length]; int[] headers = new int[columns.length]; int[] widths = new int[columns.length]; - int fixedWidth = 0; - int varWidth = 0; + int allColumnWidth = 0; int varCount = 0; // calculate @@ -132,18 +131,18 @@ public class TableView extends BaseTableView implements ItemsProvider, Sel widths[i] = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth(); varCount ++; } - if (sizeMode[i] == 0) { - fixedWidth += widths[i]; - } - else { - varWidth += widths[i]; - } + allColumnWidth += widths[i]; } - // apply: distribute available space between resizable columns but no more than *4 times. + // apply: distribute available space between resizable columns // and make sure that header will fit as well int viewWidth = getParent() != null? getParent().getWidth() : getWidth(); - int addendum = varCount > 0 && viewWidth > fixedWidth + varWidth? (viewWidth - fixedWidth - varWidth) / varCount : 0; + double gold = 0.5 * (3 - Math.sqrt(5)); + int addendum = + varCount == 0 ? 0 : (int)((allColumnWidth < gold * viewWidth ? gold * viewWidth : + allColumnWidth < (1 - gold) * viewWidth ? (1 - gold) * viewWidth : + viewWidth) - allColumnWidth) / varCount; + for (int i=0 ; i extends BaseTableView implements ItemsProvider, Sel column.setMinWidth(width); } else if (sizeMode[i] == 2) { - width = Math.max(width + Math.min(addendum, 4 * width), headers[i]); + width = Math.max(width + addendum, headers[i]); column.setPreferredWidth(width); column.setMaxWidth(width); } else if (sizeMode[i] == 3) { - width = Math.max(width + Math.min(addendum, 4 * width), headers[i]); + width = Math.max(width + addendum, headers[i]); column.setPreferredWidth(width); } }