Using styles is preferable to setting the property value. If styles are used, then you don't have the problem you describe.

An alternative, if styles are not used, is to cast the property to StyleableProperty and use applyStyle(null, value) instead of set. CSS then thinks that the value has never been set. This pattern is used, for example, in Labeled to initialize the focusTraversableProperty to false. So one option is to use applyStyle in the updateItem method rather than set. Of course, this is one of those tricks that you have to be in-the-know to make use of. But I would argue that restoreInitialPropertyState() is also a trick that you have to be in-the-know to make use of.

On 5/28/14, 6:35 AM, Tom Schindl wrote:
Hi,

All views in JavaFX are virtual and the Cell instances are reused but
this brings with it the problem that if you once modified a CSS
styleable value (e.g. the textfill, font, ...) you are unable to return
to a state where a CSS could be applied.

I think Cell needs to provide reset methods for properties who are
styleable so that one can set back the cell into a css-styleable state,
or maybe we want this to be more general and we need to provide a method
for all properties who are styled so that we can reset them?

I could imagine Node having a method: restoreInitialPropertyState()
which subclasses need to implement to restore all its properties to be
css styleable.

For Cell i think there's no way around that because it is reused and
needs to have a way to get back to the original state.

Tom

Reply via email to