Reputation: 383
I want to do global MouseClick event
to detect which node is clicked in JavaFX
. I mean when someone will click a button then event.getSource
will return me reference to this button.
Any ideas, how can i do this?
Upvotes: 1
Views: 1751
Reputation: 1919
One way to go about this would be to have a static variable somewhere that was of type Node, and then in the listener of the button, just assign a reference to the button in the handler to that button. ex:
public Class test {
public static Node whichClick;
myButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent e){
whichClick = myButton;
}
});
}
And then you could access that variable from wherever.
Upvotes: 2