当我的JSpinner为空时,我想取空值。但是当我调用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();OverLoad :或者有没有办法编辑getValue()函数?
发布于 2013-05-15 20:20:44
@user2279774:设置jSpinner为用户自定义的值。只有这样我才能知道..例如:
String[] colors = new String[] {
"Red", "Orange", "Yellow", "Green", "Blue"," ", "Purple"
};
SpinnerListModel model = new SpinnerListModel(colors);发布于 2013-05-15 20:20:32
,但当我调用getValue()函数时,它返回0.0。
使用Number格式化程序对JFormattedTextField进行肮脏的黑客攻击是不可能的,无论number实例中的数字是什么,都有默认值
当我的jSpinner为空时,我想取NULL值
在JSpinner返回double.valueOf(0.0)的情况下,返回null (错误的想法,因为数字应该用于计算)
对象a= getTextField(jValueNum).getValue();
JSpinner也可以做到这一点,没有理由使用派生编辑器来返回
发布于 2013-05-15 20:26:26
检查您设置的微调器模型。您可能已经设置了SpinnerNumberModel。尝试使用SpinnerDataModel并以字符串格式设置所有值。
它将返回为object配置的编辑器(JFormattedTextField),您将获得null作为值。:)
https://stackoverflow.com/questions/16564691
复制相似问题