gpt4 book ai didi

JavaFX Spinner.getValue()

转载 作者:行者123 更新时间:2023-12-01 17:53:54 26 4
gpt4 key购买 nike

我正在开发 JavaFX 表单。该表单应该获取值并将其添加到数据库中。每当我尝试通过 .getValue 获取值时,它都会产生错误

Incompatible Types: Object cannot be converted to Int

这是 FXML 代码:

<Spinner fx:id="spinner" layoutX="494.0" layoutY="528.0" maxWidth="100.0" minWidth="100.0" prefWidth="100.0">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory min="0" max="30" initialValue="20" amountToStepBy="1"/>
</valueFactory>
</Spinner>

Java 代码:

 Spinner mySpinner=(Spinner) spinner;
int value = mySpinner.getValue;

感谢您的帮助

最佳答案

Just posting the comment as an answer. To resolve this question:

永远不要使用原始类型。使用类似这样的东西:

Spinner<Integer> mySpinner = (Spinner<Integer>) spinner; 

关于JavaFX Spinner.getValue(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47091784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com