user12631 Asked: 2020-08-11 01:29:11 +0800 CST 2020-08-11 01:29:11 +0800 CST 2020-08-11 01:29:11 +0800 CST Simulate css hover with code 772 I want to detect when the mouse pointer hovers over a control. In CSSwould do with .miControl:hover{...}, but how do you do it in JavaFX code? javafx 3 Answers Voted Best Answer Oundroni 2020-08-11T01:37:29+08:002020-08-11T01:37:29+08:00 You have to create a listener to the property hoverPropertyof the control: miControl.hoverProperty().addListener((ov, valorAntiguo, valorNuevo) -> { if (valorNuevo == true) { // estamos encima del control } else { // estamos fuera del control } }); Jose Fanjul 2020-08-11T01:36:35+08:002020-08-11T01:36:35+08:00 You can use jQuery's is() : $('#elem').is(":hover"); // Retornaría true o false All the best! user9905 2020-08-11T01:45:18+08:002020-08-11T01:45:18+08:00 You can use Bindings. Here is a valid example for buttons and text fields: miControl.textProperty().bind( Bindings.when(miControl.hoverProperty()) .then("Estamos encima") .otherwise("Estamos fuera"));
You have to create a listener to the property
hoverProperty
of the control:You can use jQuery's is() :
All the best!
You can use Bindings. Here is a valid example for buttons and text fields: