英文:
Allow Only One Selection On CheckListView
问题
我有一个JavaFx项目,正在使用控件 CheckListView
有没有办法编写代码,使得这个控件只允许用户从 checklistview
中选择<strong>一个</strong>选项?
英文:
I have a JavaFx project and am using the control CheckListView
Is there a way to code this so that the control allows the user to only select <strong>ONE</strong> option from the checklistview
答案1
得分: 1
你可以像这样做:
checkListView.getCheckModel().getCheckedIndices().addListener(new ListChangeListener<Integer>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Integer> c) {
while (c.next()) {
if (c.wasAdded()) {
// 禁用其他单元格
}
}
}
});
英文:
You can do something like:
checkListView.getCheckModel().getCheckedIndices().addListener(new ListChangeListener<Integer>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Integer> c) {
while (c.next()) {
if (c.wasAdded()) {
// disable the rest of the cells
}
}
}
});
专注分享java语言的经验与见解,让所有开发者获益!
评论