Issue
I have created a function that will highlight the image when you hover over it.
public class HelloController {
@FXML
private ImageView exitButton;
public static void mouseWork(ImageView group){
Effect effect=group.getEffect();
group.setOnMouseEntered(mouseEvent -> {
ColorAdjust colorAdjust=new ColorAdjust(0,0,0.05,0);
group.setEffect(colorAdjust);
});
group.setOnMouseExited(mouseEvent -> group.setEffect(effect));
}
@FXML
void initialize() {
mouseWork(exitButton);
}
}
Everything works fine, but if I hover the cursor over the edge of the picture, then the image starts flashing, then adding a glow, then removing it. Why is this happening and how to fix it?
Solution
I brought the function to this form, and for some reason the problem was solved.
ColorAdjust effect= (ColorAdjust) group.getEffect();
group.setOnMouseEntered(mouseEvent -> effect.setBrightness(effect.getBrightness()+0.5));
group.setOnMouseExited(mouseEvent -> effect.setBrightness(effect.getBrightness()-0.5));
group.setOnMousePressed(mouseEvent -> effect.setBrightness(effect.getBrightness()-0.3));
group.setOnMouseReleased(mouseEvent -> effect.setBrightness(effect.getBrightness()+0.3));
Answered By - skver
Answer Checked By - Marie Seifert (JavaFixing Admin)