小编Pat*_*ein的帖子

JavaFX属性删除侦听器不起作用

我尝试添加,删除并再次添加一个JavaFx的侦听器,BooleanProperty但它无法正常工作.

这是我的代码

公共类PropListenerTest {

BooleanProperty test = new SimpleBooleanProperty(false);

public PropListenerTest() {
    System.out.println("\nTest 1\tadd the listener"); //NON-NLS
    test.addListener(this::onChangeTest);
    test.set(true);
    test.set(false);

    System.out.println("\nTest 2\tremove the listener, but not possible! Why?"); //NON-NLS
    test.removeListener(this::onChangeTest);
    test.set(true);
    test.set(false);

    System.out.println("\nTest 3\tAdd the listener again, but now i have two listener but I want only one!"); //NON-NLS
    test.addListener(this::onChangeTest);
    test.set(true);
    test.set(false);
}

private void onChangeTest(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
    System.out.println("observable = [" + observable + "], oldValue = [" + oldValue + "], …
Run Code Online (Sandbox Code Playgroud)

javafx properties listener

3
推荐指数
1
解决办法
4240
查看次数

标签 统计

javafx ×1

listener ×1

properties ×1