I have tried to do a mouse event in my JavaFX project which is when the mouse entered the background color will change and when the mouse exited will give null, but this error just keeps coming:
The method setBackground(Background) in the type Region is not applicable for the arguments (Color)
The method in my controller class:
public void barcolor(MouseEvent event) {
menubar.addEventHandler(MouseEvent.MOUSE_ENTERED, e ->
menubar.setBackground(Color.WHITE)
);
menubar.addEventHandler(MouseEvent.MOUSE_EXITED, e ->
menubar.setBackground(null)
);
}
You need to make sure that you are passing the right arguments. The setBackground() command only accepts BackgroundFill() and BackgroundImage() as arguments. Either save the background to a variable, or insert it directly into the function.