【问题标题】:Change the cycle order in a three state Checkbox in javafx在javafx中更改三态复选框的循环顺序
【发布时间】:2018-08-05 05:47:26
【问题描述】:

有没有办法改变javafx中三态Checkbox的点击顺序? 默认是检查->取消检查->不确定。
是否可以改为具有以下顺序?检查->不确定->取消选中?

关于原因的一些背景。

使用复选框的应用默认复选框为 false,这对应于需要但尚未检查的进程。
未定义状态对应于经过物理检查并被确定为错误的进程。
已检查状态对应于经过物理检查并已通过 QC 的进程。
真实案例比未定义案例更常见。

由于默认值为 false,因此下一次单击循环到未定义。 (坏)然后是真的(检查)。这些点击是针对多个进程进行的,更改顺序将大大减少用户必须进行的点击次数。

【问题讨论】:

  • 嗯……你会让你的用户感到困惑,那你为什么要这样呢?
  • 正如 kleopatra 所说,这会让用户感到困惑,并且在大多数情况下都是糟糕的设计选择。但是,您可能需要为CheckBox 设置点击监听器并自行设置状态。
  • 使用该复选框的应用程序默认该框为 false,这对应于需要但尚未检查的进程。 undef 状态是一个经过物理检查并被确定为错误的进程。检查状态是经过物理检查并通过QC的过程,真实情况比未定义情况发生的频率更高。由于默认值为 false,因此循环到的下一次单击是未定义的。 (坏)然后是真的(检查)。这些点击是针对多个进程进行的,更改顺序将大大减少用户必须进行的点击次数。
  • 感谢您的解释(您可能会考虑将其编辑到您的问题中:)嗯...也许自定义控件可能是更好的选择?不允许进行如此多的循环,而是从未经身体检查到身体检查正常或身体检查不合格的单一过渡?
  • hmm...想知道为什么不修改逻辑以适应复选框模型:checkBox.indeterminate(或未定义)== 物理未检查,checkBox.selected = =physical-checked-and-good, checkBox.unselected==physical-checked-and-bad 然后从不确定开始,切换周期如您所愿

标签: javafx checkbox


【解决方案1】:

感谢您帮助我提出建议。我现在找到了这个问题的答案。
CheckBox 类中订单的循环基于以下逻辑 https://docs.oracle.com/javafx/2/api/javafx/scene/control/CheckBox.html

checked: indeterminate == false, checked == true
unchecked: indeterminate == false, checked == false
undefined: indeterminate == true

我创建了 CheckBox 类的扩展并覆盖了 fire() 方法
下面是 CheckBox 的版本,现在可以根据需要循环。

import javafx.event.ActionEvent;
import javafx.scene.control.CheckBox;

/**
 *
 * @author returncode13
 */
public class RcheckBox extends CheckBox{


    /**
     * Toggles the state of the {@code CheckBox}. If allowIndeterminate is
     * true, then each invocation of this function will advance the CheckBox
     * through the states checked, undefined, and unchecked. If
     * allowIndeterminate is false, then the CheckBox will only cycle through
     * the checked and unchecked states, and forcing indeterminate to equal to
     * false.
     */

    @Override
    public void fire() {
        super.fire(); 
        if(!isDisabled()){

            if(isAllowIndeterminate()){
                 if(!isSelected() && !isIndeterminate()){
                    setIndeterminate(true);
                }else if(isIndeterminate()){
                    setSelected(true);
                    setIndeterminate(false);
                }else if(isSelected() && !isIndeterminate()){
                    setSelected(false);
                    setIndeterminate(false);
                }
            }else{
                setSelected(!isSelected());
                setIndeterminate(false);
            }
            fireEvent(new ActionEvent());


        }
    }

}

【讨论】:

    猜你喜欢
    • 2016-10-26
    • 2018-05-04
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    相关资源
    最近更新 更多