鼠标悬停时Imageview图像更改,Javafx

4 css javafx button imageview

我想在将鼠标悬停时通过CSS更改在imageview上设置的图像。Imageview设置在按钮上,将鼠标悬停在该按钮上时,背景颜色将更改。现在我也需要更改图像。

Ita*_*iha 5

您可以为按钮分配样式类,然后在样式表中添加新样式:

.my-button {
    -fx-graphic: url("abc.png");
}

.my-button:hover {
    -fx-graphic: url("xyz.png");
}
Run Code Online (Sandbox Code Playgroud)

哪里,

  • abc.png- >按钮上显示的图像
  • xyz.png- >要在悬停时显示的新图像
  • .my-button- >分配给按钮的样式类