如何在javafx中将背景颜色更改为imageView
问题描述:
我有一个带有透明图像(PNG)的ImageView,因此图像不会填充图像视图的完整矩形,当鼠标悬停在图像视图上时我想更改只有图像视图矩形的背景颜色。在Css我怎么做?图像视图节点是否具有属性-fx-背景颜色?我试过了,这对我不起作用。 我挂.FXML如何在javafx中将背景颜色更改为imageView
答
使用此
Bounds bound = ImageView.getBoundsInLocal(); //getting co-ordinates
ImageView.setEffect(ColorInput(bound.getMinX(), bound.getMinY(),
bound.getWidth(), bound.getHeight(), Color.YELLOW));
按功能应该工作一个CSS文件。
+0
这只是绘制了我的ImageView的颜色,现在我看不到图像。 – nhouser9
将图像视图放在'StackPane'中,并在'StackPane'上使用'-fx-background-color'。 –
'-fx-background-color',是'Region.'的属性。所以,'图像视图'没有这个属性。 – Kachna
谢谢!这工作得很好 –