Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover effect over icon

I would like to create buttons like these for settings panel navigation:

enter image description here

Can you tell me how I can create this hover effect over the icons? The most difficult part for me is to create CSS code which looks like the the picture.

like image 439
Peter Penzov Avatar asked Nov 22 '13 11:11

Peter Penzov


3 Answers

Although the above answer works. You should really do this completely in CSS using pseudo-selectors:

java:

btnsa.getStyleClass().add("myButton");

css:

.myButton {
  -fx-background-color:transparent;
}

.myButton:hover {
  -fx-background-color:#dae7f3;
}
like image 119
tomsontom Avatar answered Sep 22 '22 10:09

tomsontom


You have to use MouseEntered and MouseExited events for getting hover effects over the icons. try this its working.........

btnsa.setStyle("-fx-background-color:transparent;");
btnsa.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("JavafxSm.gif"))));

btnsa.setOnMouseEntered(new EventHandler<MouseEvent>() {

    @Override
    public void handle(MouseEvent t) {
        btnsa.setStyle("-fx-background-color:#dae7f3;");
    }
});

btnsa.setOnMouseExited(new EventHandler<MouseEvent>() {

    @Override
    public void handle(MouseEvent t) {
        btnsa.setStyle("-fx-background-color:transparent;");
    }
});

some snap shots of above code......

enter image description here

enter image description here

like image 30
Yogesh Soni Avatar answered Sep 21 '22 10:09

Yogesh Soni


Instead, you can do just 1 line code in CSS, if your FXML file connected with CSS

yourButtonId:hover{-fx-background-color: #6695e2}
like image 28
NM Naufaldo Avatar answered Sep 22 '22 10:09

NM Naufaldo