I'm building a simple login registration form and I'm trying to use a text flow to switch the scene of the primary stage but for some reason, none of the event handlers I have attempted to use are working as intended
this is what i have tried so far
TextFlow flow = new TextFlow(new Hyperlink("Dont have an account?"));
flow.setOnMouseClicked(actionEvent -> primaryStage.setScene(scene2));
Most controls in JavaFX consume mouse events by default1. That means when you click on the
Hyperlinkthe event is consumed before it can bubble up to theTextFlow, thus your event handler is never invoked.You should probably be setting the
onActionproperty of theHyperlinkanyway, as that's not only more correct semantically but also allows reacting to keyboard input in addition to mouse input. For example:As an aside: Do you need to use
TextFlowhere? If all you're doing is placing aHyperlinkwithin theTextFlowthen you should probably just be using theHyperlinkdirectly instead.1. This is done by the
javafx.scene.control.SkinBaseclass. See its#consumeMouseEvents(boolean)method.