简体   繁体   中英

JavaFX Boolean Binding for an value ContextMenuItem

I want to bind a MenuItem of my contextMenu to an specific value of the selectedValue of the tableView. Like you can see in the picture: if status is "anwesend" what is specified with an int = 2 in the Controller, then the option should be disabled.

I thought about this here, but it throws a NullPointer because the selection is empty:

contextMenuItemUnentschuldigt.disableProperty().bind(Bindings.createBooleanBinding(() -> !loggedIn || tableView.getSelectionModel().getSelectedItem().getExcused() == 2));

在此处输入图片说明

But how to check first if it's not empty and then check that it's not that specific value?

我得到了答案:

contextMenuItemUnentschuldigt.disableProperty().bind(Bindings.createBooleanBinding(() -> tableView.getSelectionModel().getSelectedItems().isEmpty() || tableView.getSelectionModel().getSelectedItem().getExcused() == 2, tableView.getSelectionModel().getSelectedItems()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM