0

我正在使用 java fxml 应用程序,并且我有一个超链接,我想在鼠标悬停时更改其颜色,并在退出鼠标时再次恢复。任何机构都可以发布一些代码来实现它。我尝试了一些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;");
    }

提前致谢。

4

2 回答 2

3

在 java 代码中设置样式对应用程序来说很重。我建议在 CSS 文件中定义它。尝试以下类似的方法来满足您的需求:

.hyperlink:hover {
    -fx-underline: true;
}
于 2013-11-27T16:36:30.567 回答
1
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
于 2013-11-27T09:25:29.753 回答