0

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);
    }
}
Sunflame
  • 2,993
  • 4
  • 24
  • 48
  • This just indicates that you have implemented the cell incorrectly. To fix the problem, you need to fix the bug(s) in your custom cell. – James_D May 11 '17 at 13:12
  • What kind of bug(s) do you refer or do you have any idea where should I look for the source of this bug? – Sunflame May 11 '17 at 13:34
  • Look in the code you have written in your custom cell implementation. I have no idea what kind of bugs might be there because I can't see the code. – James_D May 11 '17 at 13:36
  • Here is my code for the custom TTC, unfortunatelly i cannot format the code in the comment but if you copy this to a Text document u can see better: `import javafx.scene.control.cell.CheckBoxTreeTableCell; public class CustomTreeTableCheckBox extends CheckBoxTreeTableCell { @Override public void updateItem(Boolean item, boolean empty) { MyCustomRow row = getTreeTableRow().getItem(); if (row != null && row.isCondition()) { editableProperty().set(false); super.updateItem(item, empty); } else { setGraphic(null); } } }` – Sunflame May 11 '17 at 13:55
  • That's unreadable. Please put it in the question, properly formatted. – James_D May 11 '17 at 13:56
  • I also tried: `setEditable(fasle)` `setDisable(true)` `setDisabled(true)` `disableProperty().set(true)` `disabledProperty().set(true)` but none of them helped me. – Sunflame May 11 '17 at 14:09
  • For any cell, you only ever call `setEditable(false)`, but you never call `setEditable(true)`. So there is no possible way a non-editable cell can become editable again. Consequently, eventually all cells will become non-editable. – James_D May 11 '17 at 14:11

1 Answers1

1

Your updateItem method must:

  1. Always call super.updateItem(), and
  2. Update the state of the cell so that it is consistent for any possible values of item 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);
    }
}
James_D
  • 201,275
  • 16
  • 291
  • 322