Java JSpinner获取空值
当我的Java JSpinner获取空值,java,swing,isnull,jspinner,jformattedtextfield,Java,Swing,Isnull,Jspinner,Jformattedtextfield,当我的JSpinner为空时,我想取空值。但是当我调用getValue()函数时,它返回0.0 public JFormattedTextField getTextField(JSpinner spinner) { JComponent editor = spinner.getEditor(); if (editor instanceof JSpinner.DefaultEditor) { return ((JSpinner.DefaultEditor)edi
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();
编辑:或者是否有任何方法可以重载
getValue()函数
但是当我调用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;
}
}
如果没有对带有数字格式化程序的JFormattedTextField进行脏破解,这是不可能的,因为无论数字实例中的数字是什么,都有默认值
当我的jSpinner为空时,我希望获取null值
在JSpinner返回double.valueOf(0.0)的情况下返回null(错误的想法,因为数字应该用于计算)
对象a=getTextField(jValueNum).getValue()
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;
}
}
如果没有对带有数字格式化程序的JFormattedTextField进行脏破解,这是不可能的,因为无论数字实例中的数字是什么,都有默认值
当我的jSpinner为空时,我希望获取null值
在JSpinner返回double.valueOf(0.0)的情况下返回null(错误的想法,因为数字应该用于计算)
对象a=getTextField(jValueNum).getValue()
JSpinner也可以这样做,没有理由使用派生编辑器返回@user2279774:使用用户定义的值设置JSpinner。这将是我知道的唯一途径。。例如:
String[] colors = new String[] {
"Red", "Orange", "Yellow", "Green", "Blue"," ", "Purple"
};
SpinnerListModel model = new SpinnerListModel(colors);
@user2279774:使用用户定义的值设置jSpinner。这将是我知道的唯一途径。。例如:
String[] colors = new String[] {
"Red", "Orange", "Yellow", "Green", "Blue"," ", "Purple"
};
SpinnerListModel model = new SpinnerListModel(colors);
检查已设置的微调器型号。可能您已经设置了SpinnerNumberModel。尝试SpinnerDataModel并以字符串格式设置所有值
它将返回为对象配置的编辑器(JFormattedTextField),您将得到null作为值。:) 检查已设置的微调器型号。可能您已经设置了SpinnerNumberModel。尝试SpinnerDataModel并以字符串格式设置所有值
它将返回为对象配置的编辑器(JFormattedTextField),您将得到null作为值。:) 我需要一个喷丝头型号。用户应输入一个数字。但对于没有值的变量,用户应该能够将空值留空。对于JFormattedTextField,将此代码应用于JSpinnrs编辑器组件不是问题…,使用编辑器应用Documentlistener或InputVerifier,并仅接受来自用户的数字数据,但在微调器模型中内部保留为字符串。:)什么是喷丝头数据模型?我需要喷丝头编号模型。用户应输入一个数字。但对于没有值的变量,用户应该能够将空值留空。对于JFormattedTextField,将此代码应用于JSpinnrs编辑器组件不是问题…,使用编辑器应用Documentlistener或InputVerifier,并仅接受来自用户的数字数据,但在微调器模型中内部保留为字符串。:)什么是喷丝头数据模型?