Reputation: 3186
I have a TreeTableView
and I have a custom TreeTableCell in which I override the updateItem
method in order to render my cells(set disabled or enabled) depending on some condition. The problem is if I do some scroll, the table doesn't refresh, and as you can see on the attached image some cells become disabled even if they don't satisfy the condition. After heavy scrolling all cells become disabled(grayed out). I tried two things to solve the problem:
add some event listeners to refresh the table "manually" like:
treeTable.addEventFilter(ScrollEvent.ANY, event -> treeTable.refresh());
the rendering problem disappears, but if I do a little heavier scrolling, it becomes so laggy like if the application runs on 10-15 fps because the refreshing event triggers too frequently.
The other thing that I have tried is to make a timer(java.util.Timer
) to trigger the refresh for example in only every 50 milliseconds, while scrolling. Then the lag disappears but there is a delay on rendering the cells, so you can observe the change of the cell color from gray to white.
If i choose smaller time interval it becomes laggy, and i could't find a balance between the lag and delay, and I also think both of my solutions are just workarounds, not real solutions for the problem.
Do you have any other idea to solve this problem?
The attached image : TableCells
@Override
public void updateItem(Boolean item, boolean empty) {
MyCustomRow row = getTreeTableRow().getItem();
if (row != null && row.isCondition()) {
editableProperty().set(false);
super.updateItem(item, empty);
}
}
Upvotes: 0
Views: 3138
Reputation: 209330
Your updateItem
method must:
super.updateItem()
, anditem
and empty
(see the Cell
documentation.)
In your code, if the cell is used for a row where isCondition
returns true
, and then subsequently reused for a row where isCondition
returns false
, you don't revert the editable
property to true
. (So, eventually, all cells can be changed to non-editable, but can never be changed back to editable.)
You should do something like
@Override
public void updateItem(Boolean item, boolean empty) {
super.updateItem(item, empty);
MyCustomRow row = getTreeTableRow().getItem();
if (row != null && row.isCondition()) {
setEditable(false);
} else {
setEditable(true);
}
}
Upvotes: 1