简体   繁体   English

javafx节点样式转换

[英]javafx node style transition

I have a button which changes it's color when hovered over, but i want to make this color transition seem smooth. 我有一个按钮,当将鼠标悬停在上面时会更改其颜色,但是我想使此颜色过渡看起来很平滑。 How can i achieve this effect? 我怎样才能达到这种效果?

buttonLogin.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e){
                buttonLogin.setStyle("-fx-background-color: "
                                + "rgba(1, 147, 255, 0.3);"
                                + "\n-fx-border-color: "
                                + "rgba(1, 147, 255, 0.5);");
            }
        });

        buttonLogin.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e){
                buttonLogin.setStyle("-fx-background-color: "
                                + "rgba(255, 255, 255, 0.5);"
                                + "\n-fx-border-color: "
                                + "rgba(255, 255, 255, 0.8);");
            }
        });

I tried using fadetransitions, animation but i found it hard to understand. 我尝试使用淡入淡出过渡,动画,但发现很难理解。 Can someone please explain? 有人可以解释一下吗?

You need to add an event listener when the user's mouse is hovering over your button. 当用户的鼠标悬停在按钮上时,您需要添加一个事件侦听器。 About the rest, at present the only solution I know is here . 关于其余部分,目前我所知道的唯一解决方案是在这里

If I'm not mistaken, with the arrival of JavaFX 8, developers can now make animations with CSS with the new CSS API. 如果我没有记错的话,随着JavaFX 8的到来,开发人员现在可以使用具有新CSS API的CSS制作动画。 I'm just studying about it at the time. 当时我只是在研究。 Please check the link here . 请在此处检查链接。

If you need to, you can get the new version of JavaFX 8 here . 如果需要,可以在此处获取新版本的JavaFX 8。

If you have any luck, please comment. 如果您有运气,请发表评论。

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

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