java - JavaFX event handler priority -


i have custom component "default" event handler (keyevent.key_press in case). want other people able register handlers in case precedence have ability "override" default behavior.

currently handler order seems based on insertion order of handlers, handler registered first registered on creation of new instance.

how control priority of event handlers in java fx allow other people register handlers triggered before mine is?

from documentation:

a node can register more 1 handler. order in each handler called based on hierarchy of event types. handlers specific event type executed before handlers generic event types. example, handler keyevent.key_typed event called before handler inputevent.any event. order in 2 handlers @ same level executed not specified, exception handlers registered convenience methods described in working convenience methods executed last.

this implies there's no way guarantee handler invoked after client code handlers; if add handler generic event type, event.any, specific events handled before yours.

e.g.:

import javafx.application.application; import javafx.event.event; import javafx.scene.scene; import javafx.scene.input.mouseevent; import javafx.scene.layout.pane; import javafx.stage.stage;  public class eventprioritytest extends application {      @override     public void start(stage primarystage) {         pane testpane = new pane();         testpane.setfocustraversable(true);          testpane.addeventhandler(mouseevent.mouse_pressed, e ->              system.out.println("mouse pressed handler added first"));          testpane.addeventhandler(event.any, e-> {             if (e.geteventtype() == mouseevent.mouse_pressed) {                 system.out.println("generic handler added second");             }         });          testpane.setonmousepressed(e ->              system.out.println("mouse pressed handler added third via convenience method"));          testpane.addeventhandler(mouseevent.mouse_pressed, e ->              system.out.println("mouse pressed handler added fourth"));          scene scene = new scene(testpane, 400, 400);         primarystage.setscene(scene);         primarystage.show();     }      public static void main(string[] args) {         launch(args);     } } 

in example, first , fourth event handlers executed first, in no predetermined order. third event handler (since used convenience method), , second event handler (since uses generic event type).


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -