The disableProperty / disabledProperty mess
Randahl Fink Isaksen
randahl at rockit.dk
Wed Jan 15 03:43:37 PST 2014
I keep thinking we need to fix the disableProperty / disabledProperty mess, so I have created a Jira issue, which I hope you will all vote for:
Please see the description below
Randahl
———
From https://javafx-jira.kenai.com/browse/RT-35349
I know I am late to the game with this request, but please read this in full – there is a point to this.
I have used JavaFX since the early access days, and all the time I keep thinking that the disableProperty and disabledProperty of Node work in a counter-intuitive manner.
Like most other developers, I typically use names of boolean properties to express the positive state of something, as in "is it complete" or "is it ready". Usually, JavaFX property names also follow this idea, e.g. "is it visible", "is it managed", "is it pressed" and so on.
However, one property in JavaFX is reversed, and that leads to confusion. When you decide wether "is it enabled" for a Node, you do so by controlling the opposite, namely "is it disabled". To add to that confusion, there is both disableProperty and a disabledProperty.
I suggest improving JavaFX to follow almost all other GUI frameworks (including Swing), by introducing an enabledProperty. Such a property could be implemented in a backwards compatible manner by keeping the existing disableProperty but marking it as deprecated.
With an enabledProperty, there are literally thousands of lines of code in my application that would be much more readable. Today I write something like this to make a continue button be enabled when a form is complete:
continueButton.disableProperty().bind(form.validProperty().not());
– Note that above my form's validProperty expresses something positive, that the form is valid, while the button's enabled property is expressed as something negative, namely "is it NOT enabled" using the disableProperty. This requires me to use the not() method.
With the new enabledProperty() I could write code, that was more easy to read:
continueButton.enabledProperty().bind(form.validProperty());
I hope it is evident to everyone that this line is much more readable, and I think the enabledProperty would make the JavaFX API easier to use – also for newcomers learning to program JavaFX.
More information about the openjfx-dev
mailing list