简体   繁体   English

值ContextMenuItem的JavaFX布尔绑定

[英]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. 我想将contextMenu的MenuItem绑定到tableView的selectedValue的特定值。 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. 就像您在图片中看到的那样:如果状态为“ anwesend”,则在Controller中使用int = 2进行指定,则应禁用该选项。

I thought about this here, but it throws a NullPointer because the selection is empty: 我在这里考虑过这一点,但由于选择为空,因此抛出了NullPointer:

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()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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