我有一个 CTabFolder,它有很多 CTabItems。每个 CTabItem 都有一个不同的 NatTable 作为其控件。创建每个 NatTable 时,它都有列标题但没有行。当我单击“填充数据”按钮时,它将用数据填充每个表。
如果我在单击“填充数据”按钮之前查看每个选项卡,我将按预期看到列标题。然后我可以按下按钮并查看所有表格中正确填充的所有数据。
如果在单击“填充数据”按钮之前未查看选项卡,我将看不到任何列标题或数据(对于我之前未查看的选项卡)。这是因为该选项卡中的 NatTable 的宽度为 0。
我不想在单击“填充数据”按钮之前单击每个选项卡。当不集中注意事项时,在内部进行的呼叫(我可能必须手动打电话)正确设置可naterable的宽度。
以下是我的代码示例:
public void whenNatTableIsCreated(){
// Make sure the table fills the width of the parent
glazedListsGridLayer.getBodyDataLayer()
.setColumnPercentageSizing(true);
nattable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
cellPainter = new LineBorderDecorator(new
TextPainter(false, true, 5, true));
}
});
}
public void afterTableHasData() {
// Now that we have data, turn off the percentage sizing and
// allow the table width to exceed the parent width
// This fails because getNatTable().getWidth() is 0
getGlazedListsGridLayer().getBodyDataLayer().setDefaultColumnWidth(
getNatTable().getWidth() / getGlazedListsGridLayer().
getBodyDataLayer().getColumnCount());
getGlazedListsGridLayer().getBodyDataLayer()
.setColumnPercentageSizing(false);
}