ekjcfn3902039 ekjcfn3902039 - 10 months ago 82
Java Question

NatTable - Percentage Sizing with Column hiding

I would like to use column percentage sizing to force the table to take on the width of the parent.

This does not work when I hide column(s) by default because the setColumnPercentageSizing() method does not seem to exclude hidden columns and does not correctly calculate the width.

Is there an easy way to adjust this in my code?


public void example(){

public GlazedListsGridLayer createGlazedListsGridLayer(){
SortedList<T> sortedList = new SortedList<>(eventList, null);
this.bodyDataProvider = new ListDataProvider<>(sortedList,
this.bodyDataLayer = new DataLayer(this.bodyDataProvider);
ColumnHideShowLayer columnHideShowLayer = new

// In this example, hide the first column
this.bodyLayerStack = new DefaultBodyLayerStack(new
GlazedListsEventLayer<>(columnHideShowLayer, eventList));


protected void autoResizeColumns() {
nattable.addConfiguration(new DefaultNatTableStyleConfiguration() {
cellPainter = new LineBorderDecorator(new TextPainter(false,
true, 5, true));


It's not ideal but this is the closest I could get to it

public void adjustColumnWidth() {
// Avoid the first column since it's hidden
for (int x = 1; x <= numColumns; x++) {
getParent().getSize().x / numColumns, true);

Answer Source

Currently there is no solution for that. The reason for this is that the column widths are calculated in the DataLayer. The ColumnHideShowLayer sits on top of it and simply hides columns. It doesn't communicate back to the DataLayer that something is hidden.

In the end the ColumnHideShowLayer would need to re-trigger percentage size calculation based on the hidden state. But there is currently no API for that.

Feel free to create an enhancement ticket and provide a patch if you have an idea how to solve it.