2023-02-16 284
我创建了一个具有值的整数旋转器
min (5), max (15) and initialValue (12)和wrapAround (true).
一旦旋转器在增量期间达到max (15)值,而不是将值重置为min (5),如文档,它正在重置为value 10 (max (15) – min (5))
公共最终void setWraparound(布尔值)
设置属性环绕的值.
属性描述:
环绕属性用于指定价值工厂是否应为圆形.例如,应该从最大值回到最小值(反之亦然)的基于整数的值模型.
.
注意:减少正常工作,一旦达到min (5)值,旋转器值就会自动设置为max (15)
public class IntSpinnerTest extends Application
{
@Override
public void start(Stage stage) throws Exception
{
var spinner = new Spinner<Integer>();
var factory = new SpinnerValueFactory.IntegerSpinnerValueFactory(5, 15, 12);
factory.setWrapAround(true);
spinner.setValueFactory(factory);
stage.setScene(new Scene(new BorderPane(spinner), 400, 200));
stage.setTitle("IntSpinnerTest");
stage.centerOnScreen();
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
这是一个已知的错误: jdk-8193286 .提交者包括解决方法 – 概述IntegerSpinnerValueFactory:
package sample;
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
public final class IntSpinnerValueFactory extends IntegerSpinnerValueFactory {
public IntSpinnerValueFactory(final int min, final int max) {
super(min, max);
}
public IntSpinnerValueFactory(final int min, final int max, final int initialValue) {
super(min, max, initialValue, 1);
}
@Override
public void increment(final int steps) {
final int min = getMin();
final int max = getMax();
final int currentValue = getValue();
final int newIndex = currentValue + steps * getAmountToStepBy();
setValue(newIndex <= max ? newIndex : (isWrapAround() ? (newIndex - min) % (max - min + 1) + min : max));
}
}
注意:根据建议对解决方法进行了稍作修改.
我与IntegerSpinner有类似的问题 – 但在达到-11或12时将其包裹在-11至12(负到正)时,它返回到零.解决方案是用字符串制作清单旋转器.因此,使用或设置我需要将字符串转换为Integer和VC的值.
以上所述是小编给大家介绍的JavaFX整数微调器(IntegerSpinnerValueFactory)不会将值包装到最小值,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!
原文链接:https://77isp.com/post/33847.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态