我想在我的JSpinner
为空时取空值。但是当我调用getValue()
函数时,它返回0.0
。JSpinner获取空值
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()函数?
我需要一个SpinnerNumberModel。用户应该输入一个数字。但是,对于没有值的变量,用户应该可以将它留为空值。 – user2279774
[see hack](http://stackoverflow.com/a/9366053/714968)适用于JFormattedTextField,将此代码应用于JSpinnrs编辑器组件 – mKorbel
不是问题...,将Documentlistener或InputVerifier与编辑器一起使用,并仅接受数字数据来自用户,但在内部保留为微调模型中的字符串。 :) –