当我的 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/