So, what I want to do is to trigger a setOnMouseClicked event, which I created with lambda expression, without it happening, like a method call in the method start of the main class.
Asked
Active
Viewed 3,976 times
3
-
1I don't understand. Do you want to add an event handler at runtime, or trigger the event and whatever handlers are already on it? – Ben N May 03 '15 at 16:20
-
@Ben N I want to add the event handler and call it like a method in my code. – Pedro Zanutto May 03 '15 at 16:25
-
@Roland I could do that, but I'm asking this question for learning purpouse and I want to keep my code as small as possible. – Pedro Zanutto May 03 '15 at 16:25
-
I don't see a purpose for you in creating an artificial event and fire it. Unless you have a good reason to do so. Otherwise just create a method and either invoke it from your main class or from the event handler. – Roland May 03 '15 at 16:30
-
The thing is, I want the event to work as it should and call the method. – Pedro Zanutto May 03 '15 at 17:22
1 Answers
2
You need to specify object that will receive the fired event; the target is an object where the event starts and then propagates upwards through a component hierarchy:
MouseEvent mouseEvent = new MouseEvent(
MouseEvent.MOUSE_CLICKED, 1, 2, 3, 4, MouseButton.PRIMARY, 5, true, true, true, true, true, true, true, true, true, true, null);
target.fireEvent(mouseEvent);
See the javadoc for details, but seriously, don't do this.

Dave Jarvis
- 30,436
- 41
- 178
- 315

adekcz
- 340
- 2
- 13