我尝试添加,删除并再次添加一个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)