我试图将复选框绑定到多个复选框,如下所示:
private void bindPanelToPackages(CheckBox panel, CheckBox ...pkg){
BooleanProperty panelBinding = null;
BooleanBinding binder = null;
for(CheckBox p: pkg){
if(panelBinding == null){
panelBinding = p.selectedProperty();
}
else{
binder = panelBinding.and(p.selectedProperty());
}
}
if(binder != null){
panel.selectedProperty().bind(binder);
}
else if(panelBinding != null){
panel.selectedProperty().bindBidirectional(panelBinding);
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的是当'pkg'有多个项目时允许双向组绑定.这样当我选择我的包时,会自动选择'面板',或者如果我选择'面板',将选择/取消选择所有'pkg'.我被困在:
.panel.selectedProperty()结合(粘合剂);
得到了
"JavaFX Application Thread"java.lang.RuntimeException:CheckBox.selected:无法设置绑定值.
因为我为'binder'做了一个单向绑定.有没有办法可以执行与此相同的操作?:
.panel.selectedProperty()bindBidirectional(粘合剂);
我似乎无法在文档中找到它,或者我没有找到正确的地方.谢谢!