developers

    Forum Stats

  • 3,873,634 Users
  • 2,266,619 Discussions
  • 7,911,595 Comments

Discussions

Boolean OR binding with two ReadOnlyBooleanWrapper fails

csh
csh Member Posts: 525
edited May 2, 2016 5:25PM in JavaFX 2.0 and Later

Hi,

please consider the following code. I am expecting that both Labels are visible, because A || B == B || A, but only the second one is visible:

When I replace ReadOnlyBooleanWrapper with SimpleBooleanProperty it works as expected.

Feels like a bug to me?!

import javafx.application.Application;

import javafx.beans.property.BooleanProperty;

import javafx.beans.property.ReadOnlyBooleanWrapper;

import javafx.scene.Scene;

import javafx.scene.control.Label;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

public class TestApp3 extends Application {

   public static void main(String[] args) {

   launch(args);

  }

   private final BooleanProperty first = new ReadOnlyBooleanWrapper(false);

   private final BooleanProperty second = new ReadOnlyBooleanWrapper(false);

   @Override
   public void start(final Stage stage) throws Exception {

  Label label1 = new Label("first");

  Label label2 = new Label("second");

  label1.visibleProperty().bind(first.or(second));

  label2.visibleProperty().bind(second.or(first));

   first.set(true);

  Scene scene = new Scene(new VBox(label1, label2));

  stage.setScene(scene);

  stage.show();

  }

}

Answers

  • csh
    csh Member Posts: 525
    edited May 2, 2016 7:05AM
  • jsmith
    jsmith Member Posts: 2,856
    edited May 2, 2016 5:25PM

    If you declare the type of your first and second members as ReadOnlyBooleanWrapper and then bind on the read only properties retrieved from the wrappers, it works as expected.

    label1.visibleProperty().bind(first.getReadOnlyProperty().or(second.getReadOnlyProperty()));
    label2.visibleProperty().bind(second.getReadOnlyProperty().or(first.getReadOnlyProperty()));


    My guess is that the failure of the binding to be effectual on the wrappers themselves is a bug, which you could file if you wish.

      Report a Bug or Request a Feature

This discussion has been closed.
developers