Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX-在ChangeListener事件中显示警报对话框_Java_Javafx_Spinner_Alert_Changelistener - Fatal编程技术网

JavaFX-在ChangeListener事件中显示警报对话框

JavaFX-在ChangeListener事件中显示警报对话框,java,javafx,spinner,alert,changelistener,Java,Javafx,Spinner,Alert,Changelistener,我想在微调器的valueProperty更改时显示一个警报对话框。因此,我在valueProperty中添加了一个ChangeListener: this.spinnerColumns.setValueFactory(新的SpinnerValueFactory.IntegerSpinnerValueFactory(2,20)); this.spinnerColumns.getValueFactory().valueProperty().addListener((可观察、旧值、新值)->{ 如果(

我想在微调器的valueProperty更改时显示一个警报对话框。因此,我在valueProperty中添加了一个ChangeListener:

this.spinnerColumns.setValueFactory(新的SpinnerValueFactory.IntegerSpinnerValueFactory(2,20));
this.spinnerColumns.getValueFactory().valueProperty().addListener((可观察、旧值、新值)->{
如果(旧值>新值){
//请求许可
System.out.println(“请求许可”);
Alert Alert=新警报(Alert.AlertType.WARNING);
警报。设置标题(“错误”);
警惕。setHeaderText(“询问某事…”);
alert.showAndWait();
if(alert.getResult()==ButtonType.OK){
//做点什么
}
}
});

此代码工作不正常。当警报显示时,微调器会不断减小其值,直到达到最小值。如何做到这一点的一些建议

据我所知,不使用反射就很难停止旋转。。。试试这个代码

if(oldValue > newValue) {

    try {
        Skin<?> skin = this.spinnerColumns.getSkin();
        Object behavior = skin.getClass().getMethod("getBehavior").invoke(skin);
        behavior.getClass().getMethod("stopSpinning").invoke(behavior);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
        return; // If refleciton failed, do nothing
    }

    // Ask for permission
if(旧值>新值){
试一试{
Skin Skin=this.spinnerColumns.getSkin();
对象行为=skin.getClass().getMethod(“getBehavior”).invoke(skin);
behavior.getClass().getMethod(“停止旋转”).invoke(行为);
}捕获(NoSuchMethodException | IllegalacessException | InvocationTargetException e){
e、 printStackTrace();
return;//如果reflection失败,则不执行任何操作
}
//请求许可

据我所知,不使用反射就很难停止旋转…请尝试以下代码

if(oldValue > newValue) {

    try {
        Skin<?> skin = this.spinnerColumns.getSkin();
        Object behavior = skin.getClass().getMethod("getBehavior").invoke(skin);
        behavior.getClass().getMethod("stopSpinning").invoke(behavior);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
        return; // If refleciton failed, do nothing
    }

    // Ask for permission
if(旧值>新值){
试一试{
Skin Skin=this.spinnerColumns.getSkin();
对象行为=skin.getClass().getMethod(“getBehavior”).invoke(skin);
behavior.getClass().getMethod(“停止旋转”).invoke(行为);
}捕获(NoSuchMethodException | IllegalacessException | InvocationTargetException e){
e、 printStackTrace();
return;//如果reflection失败,则不执行任何操作
}
//请求许可