Keyboard events
Richard Bair
richard.bair at oracle.com
Mon Oct 7 07:53:43 PDT 2013
That being said, this seems like a very common use case, and I wonder if there is something more we could do (in the longer term, short term do as Artem suggests)
> On Oct 7, 2013, at 3:56 AM, Artem Ananiev <artem.ananiev at oracle.com> wrote:
>
>
>> On 10/7/2013 2:40 AM, Pedro Duque Vieira wrote:
>> Hi,
>>
>> I have the following use case:
>> When the user presses shift and the mouse is hover the chart component the
>> cursor must change to an open hand cursor signaling to the user that the
>> chart is ready for a panning action.
>> The problem is that for this to be possible I want the chart to be able to
>> listen to keyboard events even when it doesn't have focus.
>>
>> I think this is not possible and I wonder why. Swing was the same, you
>> could only listen to keyboard events if the control had focus. Is this a
>> technical limitation? If there is no technical limitation I think it would
>> be better to remove this restriction, I think it is limiting and the above
>> scenario is a good use case to show that.
>
> This is not a technical limitation, it's just the way how it's supposed to work. All the key events are dispatched to the component in focus, this is what input focus is.
>
> Scenario you described should be easier to implement in FX than in Swing. In AWT/Swing, input events are dispatched to a single component, while FX is much more flexible. All the events are delivered to a Scene first, then dispatched to the focused component (or component under mouse, for mouse events), then bubbled up back to the Scene. What you need is to register a custom event filter for the scene and listen to all the key events.
>
> See Scene.addEventFilter() and Scene.addEventHandler() for details.
>
> Thanks,
>
> Artem
>
>> Thanks, best regards,
>>
More information about the openjfx-dev
mailing list