Suzan Cioc
Suzan Cioc

Reputation: 30147

How to prevent of selecting another row in TableView in JavaFX

Suppose, I would like to implement data validation in JavaFX TableView.

Once user have changed data in the row, I would like to check it when user is trying to change current row number. Once data is correct, I would like to allow row change, once data is incorrect, I want to disallow this.

How to implement this?

Currently, I am trying to add a listener

getSelectionModel().selectedIndexProperty().addListener(indexFromTableToModel);

but any operations inside it causes bad table view behavior. Using

Platform.runLater

makes situation better, but still imperfect.

Is there a convenient place, to perform row data validation and perform different operation depending on it?

Upvotes: 1

Views: 308

Answers (1)

Hendrik Ebbers
Hendrik Ebbers

Reputation: 2600

You can write your own selection model that can be locked (if current value is invalid). In that case the model won't change the internal selected index.

Upvotes: 3

Related Questions