javafx - Disabling Button while TextFields empty not working -
booleanbinding bb = new booleanbinding() { { super.bind(addnum.textproperty(),addt1.textproperty(),addt2.textproperty(), addt3.textproperty(),addasg.textproperty(),addatt.textproperty()); } @override protected boolean computevalue() { return (addnum.gettext().isempty() && addt1.gettext().isempty() && addt2.gettext().isempty() && addt3.gettext().isempty() && addasg.gettext().isempty() && addatt.gettext().isempty()); } }; final button b2 = new button("add"); b2.disableproperty().bind(bb);
this code disable button when textfields empty, button becomes active when textfield filled. code not working. when 1 textfield filled button becomes active. had used code @ other parts of project same purpose add working fine there. why not working here ?
if want button
active if , if fields filled (i.e. not empty), using wrong operator. use ||
instead of &&
make work.
you can easyly see what's wrong, if reformulate formula computevalue
using demorgan's laws; write
a1, a2, ..., a6
instead of
`addnum.gettext().isempty()`, `addt1.gettext().isempty()`, ..., `addatt.gettext().isempty()`:
the following statements equivalent:
- the button active
!(a1 && a2 && ... && a6)
(!a1 || !a2 ||...|| !a6)
- at least 1 field filled
in contrast ||
instead of &&
:
the following statements equivalent:
- the button active
!(a1 || a2 || ... || a6)
(!a1 && !a2 &&...&& !a6)
- all fields filled
Comments
Post a Comment