我有一个CTabFolder,它有许多CTabItems。每个CTabItem与其控件都有不同的NatTable。当每个NatTable被创建时,它都有列标题但没有行。当我点击一个“填充数据”按钮时,它将用数据填充每个表格。CTabItem中的NatTable宽度
如果在单击“填充数据”按钮之前查看每个选项卡,我将按预期看到列标题。然后我可以按下按钮并查看所有表格中正确填充的所有数据。
如果我在单击“填充数据”按钮之前不查看选项卡,我将看不到任何列标题或数据(对于之前没有查看的选项卡)。这是因为该选项卡中的NatTable的宽度为0.
我不想在单击“填充数据”按钮之前单击每个选项卡。内部进行的调用(我可能需要手动调用)才能正确设置选项卡未聚焦时的NatTable宽度。
下面是我的代码示例:
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);
}
我使用百分比大小来确保列名跨越整个父宽度。没有那个电话他们不会。如果有人在填充数据之前查看表格,我想要将表格显示为与父表格相同的宽度(即使没有数据,仍然会显示列名称) – ekjcfn3902039