简体   繁体   English

javafx和css代码来更改鼠标悬停时的超链接颜色

[英]javafx and css code to change hyperlink color on mouse hover

I am working with java fxml application and i have one hyperlink, I want to change its color when mouse is over it and again revert back when mouse is exited from it. 我正在使用java fxml应用程序,并且我有一个超链接,当鼠标悬停在其上时,我想更改其颜色;当鼠标从其退出时,我再次将其还原。 Can any body post some code to achieve it. 任何机构都可以发布一些代码来实现它。 I tried some css code but not working, 我尝试了一些CSS代码,但无法正常工作,

On mouse entered:-
 @FXML
    private void changeCloseColorToWhite() {
        hypLnkClose.setStyle("-fx-color: white;");
    }

On mouse exited:-
@FXML
    private void changeCloseColorToBrown() {
        hypLnkClose.setStyle("-fx-color: #606060;");
    }

Thanks in advance. 提前致谢。

Setting style in java code is heavy on the application. 在Java代码中设置样式在应用程序上很繁琐。 I would suggest defining this in the CSS file. 我建议在CSS文件中定义它。 try something like this below to fulfill what you need: 请尝试以下类似方法来满足您的需求:

.hyperlink:hover {
    -fx-underline: true;
}
You can also do like this
your_file.fxml(This is you .fxml file)
<Hyperlink text="you text to being hyperlink" styleClass="myLink">


your_style.css(This is your styleSheet file)

.myLink{
   -fx-text-fill: white;
       }
.myLink:hover{
   -fx-text-fill: #606060;
        }

This will also work fine. So try it

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

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