java - JSpinner 获取空值

标签 java swing isnull jspinner jformattedtextfield

当我的 JSpinner 为空时,我想采用 null 值。但当我调用 getValue() 函数时,它返回 0.0

  public JFormattedTextField getTextField(JSpinner spinner) {
    JComponent editor = spinner.getEditor();
    if (editor instanceof JSpinner.DefaultEditor) {
        return ((JSpinner.DefaultEditor)editor).getTextField();
    } else {
        return null;
    }
}

这是我的方法调用:

Object a = getTextField(jValueNum).getValue();

编辑:或者有什么方法可以过载 getValue() 函数?

最佳答案

@user2279774:使用用户定义的值设置 jSpinner。这将是我知道的唯一方式..例如:

String[] colors = new String[] {
                "Red", "Orange", "Yellow", "Green", "Blue","  ", "Purple"
        };
        SpinnerListModel model = new SpinnerListModel(colors);

关于java - JSpinner 获取空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16564691/

相关文章:

java - ClassCastException:使用 DialogFragment 时应用程序崩溃

java - 非法状态异常 : getwriter() has already been called for this response

java - 在java中将一维数组转换为多维数组

Java GridBagLayout - 如何将我的组件一一无间隙地定位?

java - JFrame 的比例调整大小

php - LEFT JOIN 不显示 NULL 结果

java - model.addAttribute() 参数

java - 当用户在文本字段中输入 Java Swing 时屏蔽 IP 地址

java - Java中如何将null转为false?

python - Pandas 相当于列修改语句的 isnull