Use*_*ser 1 java javafx javafx-8
是否可以在任意节点/区域/窗格上执行渐渐变浅的简单背景“闪光”效果?
我只想在VBox(包含标签)上显示微妙/简短的红色/白色“闪光”效果,以在标签值更改时引起注意。
编辑:到目前为止,我发现的所有这种性质的示例似乎都使用“ Shape”(这是一个Node),但是VBox或Pane当然不是Shape,因此对我没有太大帮助。在VBox上调用getShape()只会返回一个null,所以这无济于事(我想还没有执行布局代码)。
编辑2:此ALMOST起作用,但此悬挂效果似乎完全覆盖了(我认为)VBox中的所有内容,包括文本Label。
ColorInput effect = new ColorInput(0, 0, 900, 25, Paint.valueOf("#FFDDDD"));
Timeline flash = new Timeline(
new KeyFrame(Duration.seconds(0.4), new KeyValue(effect.paintProperty(), Paint.valueOf("#EED9D9"))),
new KeyFrame(Duration.seconds(0.8), new KeyValue(effect.paintProperty(), Paint.valueOf("#E0DDDD"))),
new KeyFrame(Duration.seconds(1.0), new KeyValue(effect.paintProperty(), Paint.valueOf("#DDDDDD"))));
vbox.setEffect(effect);
flash.setOnFinished(e -> vbox.setEffect(null));
flash.play();
Run Code Online (Sandbox Code Playgroud)
最好的方法是提供一个自定义动画,如下所示(详细说明了fabian的答案):
@Override
public void start(Stage primaryStage) {
Label label = new Label("Bla bla bla bla");
Button btn = new Button("flash");
VBox box = new VBox(10, label, btn);
box.setPadding(new Insets(10));
btn.setOnAction((ActionEvent event) -> {
//**************************
//this animation changes the background color
//of the VBox from red with opacity=1
//to red with opacity=0
//**************************
final Animation animation = new Transition() {
{
setCycleDuration(Duration.millis(1000));
setInterpolator(Interpolator.EASE_OUT);
}
@Override
protected void interpolate(double frac) {
Color vColor = new Color(1, 0, 0, 1 - frac);
box.setBackground(new Background(new BackgroundFill(vColor, CornerRadii.EMPTY, Insets.EMPTY)));
}
};
animation.play();
});
Scene scene = new Scene(box, 100, 100);
primaryStage.setScene(scene);
primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5043 次 |
| 最近记录: |