简体   繁体   English

如何在javafx中将背景颜色更改为imageView

[英]how to change background color to imageView in javafx

I have a ImageView with a transparent image (PNG) therefore the image doesn't fill the complete rectangle of the image view, when mouse hover over the image view I want to change the background color of only the rectangle of the image view. 我有一个带有透明图像(PNG)的ImageView,因此该图像无法填充图像视图的整个矩形,当鼠标悬停在图像视图上时,我只想更改图像视图矩形的背景色。 In Css how I do it? 在CSS中我该怎么做? do the image view node have the property -fx-background color? 图像视图节点是否具有-fx-background color属性? I tried and it's doesn't work for me. 我尝试过,但对我不起作用。 I have a css file linked to the .FXML 我有一个链接到.FXML的CSS文件

Use this 用这个

Bounds bound = ImageView.getBoundsInLocal(); //getting co-ordinates
ImageView.setEffect(ColorInput(bound.getMinX(), bound.getMinY(),
            bound.getWidth(), bound.getHeight(), Color.YELLOW));

By function should work. 按功能应该起作用。

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

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