how to implement JavaFX property "throwing" exception

Werner Lehmann lehmann at media-interactive.de
Fri Apr 5 11:10:51 PDT 2013


I think that invalidated() is called after the fact. It is too late to 
veto the value.

Instead I override set(). Maybe setValue() would be better, not sure. It 
would be your call to accept potential binding implications (might be ok 
for non-library code).

Werner

On 05.04.2013 18:33, Vasiliy Baranov wrote:
>       private StringProperty foo;
>
>       public final StringProperty fooProperty() {
>           if (foo == null) {
>               foo = new SimpleStringProperty(this, "foo") {
>                   @Override protected void invalidated() {
>                       if (!isInAppropriateState()) {
>                           throw new IllegalStateException();
>                       }
>                   }
>               };
>           }
>           return foo;
>       }


More information about the openjfx-dev mailing list