I have created an error effect, that I set on TextFields and animate it, if user inputs incorrect data values.
public class ErrorEffect extends DropShadow {
private Timeline animation = new Timeline();
public ErrorEffect() {
setOffsetX(0);
setOffsetY(0);
setRadius(0);
setColor(Color.RED);
animation.getKeyFrames().addAll(
new KeyFrame(Duration.ZERO, new KeyValue(radiusProperty(), 0)),
new KeyFrame(new Duration(150), new KeyValue(radiusProperty(), 20)),
new KeyFrame(new Duration(500), new KeyValue(radiusProperty(), 0)));
}
public Timeline getAnimation() {
return animation;
}
}
My problem is whenever TextField is disabled, it displays DropShadow's color. Normally red color cannot be seen since its radius is set to 0 and radius changes only during animation.
If I use a different effect like an InnerShadow this does not happen, disabled TextFields have default color and do not inherit InnerShadows color.
I want to make this work with a DropShadow, but I cannot understand why this even happen, but doesn't happen with InnerShaddow.
I have tried DVarga's solution, but I have got strange results.
I realized it was not a color issue, but rather an opacity one.
Googlin for similar opacity issues I came across this answer, its a quite different problem, but I still tried the solution and it worked: https://stackoverflow.com/a/35712919/2821023
Seems like it is a bug and opacity gets applied twice. It was reported already, so there is a possibility it will get fixed someday. Also the answer explained why disabled components in ScrollPane are much lighter, see the picture above. There seems to be a lot of issues with disabled components in a javafx...
So, I solved my issue by setting opacity to 1 on my TextFields.
textField.setOpacity(1);
Edit:
Ok, I thought it was something with initialization, so setting opacity after component was initialized solved it.
However I tried setting opacity through fxml:
<TextField fx:id="groupTextField" promptText="Group" opacity="1" />
And it still works, I even get a warning saying:
Attribute is redundant because it contains default value
Can anyone explain what is going on here? How setting the same opacity value on the component it currently has could solve anything?