In fx, mouseEvents aren't dispatched to disabled nodes, at the end is a quick example demonstrating the behaviour.
For a Swinger like me, that's a bit surprising: in my land, events are delivered and it's the task of the target (ui-delegate) to decide whether or not the event should be handled. Actually was pointed to this by a recent - perfectly valid, IMO - use-case of showing a tooltip over a disabled component
Technically, the dispatch seems to be cut off in one of Node's impl methods:
/**
* Finds a top-most child node that intersects the given ray.
*
* The result argument is used for storing the picking result.
*/
@Deprecated
public final void impl_pickNode(PickRay pickRay, PickResultChooser result) {
// In some conditions we can omit picking this node or subgraph
if (!isVisible() || isDisable() || isMouseTransparent()) {
return;
}
which seems to be called during the hit detection process. If so, it would be really deep down in the bowels without much of chance to tweak.
The questions:
- anything wrong with my code (could easily have missed something obvious ;-)
- is the above really the underlying reason?
- is there any configurable option to force the dispatch? If so, how-to?
- where's the spec of the behaviour? Looked around tutorials/api doc but couldn't find anything.
Code example:
package fx.control;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
/**
* @author Jeanette Winzenburg, Berlin
*/
public class MouseEventDisabled extends Application {
private Parent getContent() {
Pane parent = new Pane();
Rectangle r = new Rectangle(100, 100, 200, 200);
r.addEventHandler(MouseEvent.ANY, event -> System.out.println(event));
CheckBox button = new CheckBox("rectangle disabled");
r.disableProperty().bind(button.selectedProperty());
parent.getChildren().addAll(r, button);
return parent;
}
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = getContent();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch();
}
}