简体   繁体   English

如何在FadeTransition中添加多个按钮?

[英]How to add more than one button to a FadeTransition?

I have a program for school trying to create a vending machine and I'm trying to get more than one button to be a bake to do a fade transition off the same transition! 我有一个用于学校的程序,试图创建一个自动售货机,并且我试图使多个按钮成为烘焙对象,以从同一过渡中淡出过渡! Is this possible or do I have to have an entirely different fade transition for each button? 这是否可能,或者每个按钮是否必须具有完全不同的淡入淡出过渡?

FadeTransition ft = new FadeTransition();
ft.setNode(imgView1);
ft.setDuration(Duration.millis(5000));
ft.setFromValue(1.0);
ft.setToValue(0.0);
ft.setCycleCount(1);
ft.setAutoReverse(true);
ft.plat();

btn1.setOnMousePressed(e->ft.play());

I have 3 other buttons and images I want to do the same thing with but not sure if I have to make each Seperated FadeTransition or if I can add them to this one? 我还有3个其他按钮和图像,我想使用它们来做同样的事情,但是不确定是否必须进行每个Sepedated FadeTransition或是否可以将它们添加到此按钮中?

Unless the nodes are the only ones in a common parent that has no visuals, you cannot apply the transition to more than one node. 除非这些节点是公共父级中唯一没有视觉效果的节点,否则您不能将过渡应用于多个节点。

You could however bind the opacity property of the other nodes to the opacity of the animated node: 但是,您可以将其他节点的opacity属性绑定到动画节点的opacity

node2.opacityProperty().bind(imgView1.opacityProperty());
node3.opacityProperty().bind(imgView1.opacityProperty());

You could also create a Timeline with a KeyValue element for every node: 您还可以为每个节点创建一个带有KeyValue元素的Timeline

Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO,
                                              new KeyValue(node1.opacityProperty(), 1d),
                                              new KeyValue(node2.opacityProperty(), 1d),
                                              new KeyValue(node3.opacityProperty(), 1d)),
                                 new KeyFrame(Duration.seconds(5),
                                              new KeyValue(node1.opacityProperty(), 0d),
                                              new KeyValue(node2.opacityProperty(), 0d),
                                              new KeyValue(node3.opacityProperty(), 0d)));

timeline.setAutoReverse(true);
timeline.play();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM