NatTable - 设置动态列宽

时间:2016-10-27 13:30:02

标签: java nattable

我想让NatTable的列动态扩展到

  • 显示单元格中的整个值
  • 完全填充父组合

看来我可以做其中一个,但不能两个都做。换句话说,如果我有一个大的父复合并且NatTable只有几个非常短的列,我会有很多空白(也就是说,与父复合材料宽度相比,NatTable的宽度会很小) / p>

我尝试了以下代码段:

// This sets the full width of the Composite, but all columns are equal 
// width. If a column has a long value, the value will be truncated.
glazedListsGridLayer.getBodyDataLayer().setColumnPercentageSizing(true);

// This auto-resizes the columns based on their values. If the values
// are short, this table will not fill the width of the composite
nattable.addConfiguration(new DefaultNatTableStyleConfiguration() { {
  cellPainter = new LineBorderDecorator(new TextPainter(false, true, 5, true));}
});

我想我正在寻找一种混合,其中列将根据值自动调​​整大小。如果表格没有填满复合材料的宽度,我想要:

  • 所有列均匀地添加额外的宽度,直到该表与Composite父级或
  • 的大小相同
  • 特定列将添加额外宽度,直到该表与Composite父级
  • 相同

如果表填充了Composite的整个宽度并且列值很长,我想确保该表有一个水平滚动条(必要时)以查看所有列及其非截断值

有没有人对如何实现这一点有任何见解? 谢谢!

1 个答案:

答案 0 :(得分:1)

目前不支持指定最小宽度。但如果它只是一个视觉效果,你可以尝试使用在整个可用空间上打印的NatGridLayerPainter。这就像一个额外的列,但实际上没有添加列。

NatTable natTable = new NatTable(parent);
NatGridLayerPainter layerPainter = new NatGridLayerPainter(natTable);
natTable.setLayerPainter(layerPainter);