设置列标题的最大高度-NatTable

时间:2019-06-27 16:10:02

标签: java swt nattable

我有使用l=[] for x, y in df.groupby('author'): s = y.Year.values a = s - s[:, None] l.append([y.co_author[x].unique() for x in (np.logical_and(a >= 0, a <= 2))]) df=pd.DataFrame({'author':df.author, 'Year':df.Year.astype(str)+'-'+(df.Year+2).astype(str), 'co_authors_list':np.concatenate(l)}).\ drop_duplicates(['author','Year']) df Out[337]: author Year co_authors_list 0 A 1990-1992 [B, C] 2 A 1991-1993 [B] 3 A 1994-1996 [D] 4 A 1995-1997 [D] 5 B 1990-1992 [A, C, E] 6 B 1991-1993 [C, E] 8 B 1998-2000 [C] 的列标题。

如果我将VerticalTextPaintersetCalculateByTextHeight设置为true,则将调整列的大小以正确适合单元格内的所有文本。

有时标头中会包含很多文本,所以我希望它们具有最大高度。

如果我停止使用setCalculateByTextLengthsetCalculateByTextHeight,则单元格根本不会调整大小,因此它们只显示setCalculateByTextLength

我该怎么做呢?

更新

...

在NatTable中覆盖paintControl

@Override
protected void setNewMinLength(ILayerCell cell, int contentHeight) {

    final ILayer layer = cell.getLayer();
    final int cellLength = cell.getBounds().height;

    if (contentHeight < MAXIMUM_HEIGHT && cellLength < contentHeight) {
        layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight));
    } else {
        layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), MAXIMUM_HEIGHT));
    }
}

1 个答案:

答案 0 :(得分:0)

没有内置机制来指定最大高度或宽度。您可以配置根据高度计算高度,也可以设置固定高度。

我认为您可以通过将VerticalTextPainter子类化并重写setNewMinLength()来仅在contentHeight大于cellLength且cellLength不大于最大值时执行RowResizeCommand来实现。当然,RowResizeCommand只能重新设置为您指定的最大值。

在其他任何地方执行检查可能会导致无休止地处理像元高度调整大小。

相关问题