[英]How do you clear a Spinner within an event handler
When I press a button, I want the spinner value to reset to 0 within an event handler.当我按下按钮时,我希望微调器值在事件处理程序中重置为 0。
Currently I have something like this:目前我有这样的事情:
Spinner sp = new Spinner();
int shAge;
....
EventHandler submitH = new EventHandler() {
@Override
public void handle(Event event) {
int shAge = Integer.parseInt(sp.getValue().toString());
....
System.out.println(shAge);
.....
and logically in my mind, to clear the spinner after the value has been added to an array list, there should be something like从逻辑上讲,在将值添加到数组列表后清除微调器,应该有类似的东西
sp.clear();
or或者
sp.reset();
however I can't seem to find anything like that when looking in the documentation.但是在查看文档时我似乎找不到类似的东西。
If you only want to reset the value to 0
you can do:如果您只想将值重置为
0
您可以执行以下操作:
sp.getValueFactory().setValue(0);
If you really want to clear the spinner you can additionally do:如果您真的想清除微调器,您还可以执行以下操作:
sp.getEditor().clear();
But be aware that clearing the editor seems to be not fully supported.但请注意,似乎不完全支持清除编辑器。 Using the increment and decrement buttons after that will throw a NullPointerException for example.
例如,在此之后使用递增和递减按钮将抛出 NullPointerException。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.