I have a use case which I would assume is pretty standard, however I haven't been able to find an example on exactly how to do this, or if it's possible.
Let's assume I have the following TableView
First Name Last Name Street NewRecord
Tom Smith Main St. Yes
Mike Smith First St. No
In this case, the grid should have the first three cells editable since the record is new, however when the record is not new then the Last Name cell should be disabled.
I tried this in the CellFactory and RowFactory - but haven't seen a way to accomplish this.
Thanks for your help.
The easiest way to do this is with a third-party binding library: ReactFX 2.0 has this functionality built-in, as described here. Using that you can do
(assumes a
Person
table model object with the obvious JavaFX properties and methods).Without the library, you need a pretty miserable nested list of listeners:
and then
An alternative using a "legacy style" API is
I dislike this option, because it lacks any type safety (or indeed any compiler checks at all), and additionally in some earlier versions of JavaFX would generate almost endless warning messages if any of the properties in the "chain" had null values (which they will, frequently, in this case). I believe the latter issue is fixed, but the ReactFX version of this is far better, imho.
You can always stop an editing by setting event handler to check if the action is legal.