Search code examples
listviewcelljavafx-2

Java Fx 2: Refresh item color in ListView


Help! I can't figure this one out. I'm trying to make a ListView where the color of the text item changes when the user clicks on it. The same way hyperlinks indicate if they have been visited.

I wrote a custom Cell Factory that does this, the problem is that the Cell factory is not being called when I click on an item.

I tried to work around this by actually changing the VALUE of the item in order to get the cell factory to be called, however, here's the problem: if I change the VALUE from within the ChangeListener which I set up to monitor if a user clicks on a new item, it's going to call my ChangeListener AGAIN, and then it becomes an infinite loop. Any ideas? Thanks


Solution

  • You can add mouse listener to your cell factory and change color from it.