Search code examples
event-handlingtableviewjavafx-8event-bubbling

JavaFX TableView not Bubbling Events to Parent


Context: Not sure if this is a bug or a feature, but I am contributing to a JavaFX application that has an autolock feature that kicks in if there is no activity over a certain duration. If however, the activity occurs within the bounds of a JavaFX TableView widget/control, all input/mouse activity, whether movement, selecting or clicking, is not detected as activity (to reset the timer that listens for activity), so the autolock feature throws a warning to the user and subsequently locks, even if they have been performing activity within a TableView in the application.

Inquiry: Does anyone know if this is a "feature" that can be toggled on/off, so parent controls can be aware of activity within a child TableView? Or does one need to manually wire up an event handler specifically for bubbling any input events in a TableView to the parent control/container?


Solution

  • Use capturing rather than bubbling. You can do this in JavaFX using event filters, which can be set on Stages or Scenes or individual Nodes (whichever is most applicable to your requirements).

    For the functionality you seem to require (application input inactivity monitor), capturing at the stage or scene level seems more appropriate than bubbling. Events can be consumed during the bubbling phase (by design), so higher level bubbling listeners would not receive them. However, you can intercept the same events during the capturing phase to take action on them before they get consumed.