只允许在CheckListView上进行一次选择。

huangapple go评论65阅读模式
英文:

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&lt;Integer&gt;() {
        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change&lt;? extends Integer&gt; c) {
            while (c.next()) {
                if (c.wasAdded()) {
                 // disable the rest of the cells
                }
            }
        }
    });

huangapple
  • 本文由 发表于 2020年4月9日 04:29:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/61109477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定