JavaFX-在ChangeListener事件中显示警报对话框
我想在微调器的valueProperty更改时显示一个警报对话框。因此,我在valueProperty中添加了一个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((可观察、旧值、新值)->{ 如果(
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失败,则不执行任何操作
}
//请求许可