final JTableHeader header = myTreeTableView.getTableHeader();
final FontMetrics fontMetrics = header.getFontMetrics(header.getFont());
int maxPreferredWidth = 0;
TableColumn treeColumn = null;
for (int i = 0; i < columnInfos.length; i++) {
final ColumnInfo columnInfo = columnInfos[i];
final TableColumn column = columnModel.getColumn(i);
final String name = columnInfo.getName();
final int minWidth = StringUtil.isNotEmpty(name.trim()) ? fontMetrics.stringWidth(name) + 15 : 0;
column.setMinWidth(minWidth);
if (TreeTableModel.class.isAssignableFrom(columnInfo.getColumnClass())) {
treeColumn = column;
final int preferredWidth = myTreeTableView.getTree().getSize().width;
column.setPreferredWidth(preferredWidth);
if (preferredWidth > minWidth) {
column.setMinWidth(preferredWidth);
}
}
else if (!(columnInfo instanceof JamSpacerColumnInfo)) {
final int fixedWidth = columnInfo.getWidth(myTreeTableView);
if (fixedWidth > 0) {
final int realWidth = Math.max(minWidth, fixedWidth);
column.setMaxWidth(realWidth);
column.setMinWidth(realWidth);
column.setPreferredWidth(realWidth);
}
else {
int preferredWidth = minWidth;
final String preferredValue = columnInfo.getPreferredStringValue();
if (preferredValue != null) {
preferredWidth = Math.max(preferredWidth, fontMetrics.stringWidth(preferredValue));
}
column.setPreferredWidth(preferredWidth + columnInfo.getAdditionalWidth());
final String maxValue = columnInfo.getMaxStringValue();
if (maxValue != null) {
column.setMaxWidth(fontMetrics.stringWidth(preferredValue) + columnInfo.getAdditionalWidth());
}
}
}
maxPreferredWidth = Math.max(maxPreferredWidth, column.getPreferredWidth());
}