I would like to have some guidance about the JavaFX CSS, the question / problem is this:
I'm trying to create the Hover
effect in an ImageView which starts with a opacity of 0.5 ; the question is to create a Style Sheet which calls Efectos.css
in which I have the code that makes the effect (I upload a screenshot to be clearer). The fact is that he used the btn_cerrar.getStyleClass().add("imageview");
command but does not create any effect.
Effects.css:
On the other hand, I had thought to leave the CSS and do this effect with code (JavaFX) where I create the following code:
This is created in the FXMLController:
@FXML
private void efectosMouse(MouseEvent event){
btn_cerrar.setOnMouseEntered((MouseEvent event1) -> {
btn_cerrar.setStyle("-fx-opacity: 1");
});
btn_cerrar.setOnMouseExited((MouseEvent event1) -> {
btn_cerrar.setStyle("-fx-opacity: 0.5");
});
}
The problem is that this same code will be re-used in other elements of ImageView type, to which, I do not want to repeat these lines throughout the code of my program. Is it possible to create this code in a class and go to the class when you need it?
IDE's:
- Netbeans.
- SceneBuilder 2.0.
PS: I hope to be clear with my doubts, I thank you in advance for your comments.