0

I found this post for connecting a Java Bean as property binding with an existing JavaFX property. The binding should target a boolean property:

class MyClass {

    private boolean loaded;

    public boolean isLoaded() {

        return loaded;
    }

    // Value changed internally
}

For real beans, meaning beans with setters the following works like a charm. But I've the problem that there's no setter for the loaded property, just because it's set internally and shouldn't be modifyable for external classes.

BooleanProperty loadedProeprty = new JavaBeanBooleanPropertyBuilder()
    .bean(bean)
    .name("loaded")
    .getter("isLoaded")
    .build();

Is there any way to create still a property for such "beans" without a setter? For now I just get a NoSuchMethodException for the expected setter MyClass.setLoaded(boolean).

0x1C1B
  • 1,204
  • 11
  • 40

1 Answers1

0

Use ReadOnlyJavaBeanBooleanPropertyBuilder instead.

Normal properties in JavaFX are always read/write and thus require a setter. The read only variant creates a read only property and thus does not require a setter.

john16384
  • 7,800
  • 2
  • 30
  • 44
  • 2
    Some explanation as to why this will solve the problem would make this a much better answer. – Nick May 11 '19 at 02:44