artem.ananiev at oracle.com
Mon Oct 7 10:00:24 PDT 2013
On 10/7/2013 6:57 PM, Pedro Duque Vieira wrote:
> Hi Artem, Richard,
> Thanks for your feedback! There's one more thing which further
> complicates things and that I've forgot to mention. The chart is
> embedded in a swing app, so doing as Artem suggests will not work: the
> scene will have to be focused in order for it to receive keyboard
> events, right?
For standalone FX apps (no Swing), it's required and enough to have FX
scene focused. With Swing involved, things get more complicated. FX
scene is considered to have focus, if the corresponding JFXPanel is
focused (as a Swing component). Only in that case you'll be able to
track key events using the event filters/handlers, otherwise you'll have
to use Toolkit.addAWTEventListener() or something like this.
> Thanks, best regards,
> On Mon, Oct 7, 2013 at 3:53 PM, Richard Bair <richard.bair at oracle.com
> <mailto:richard.bair at oracle.com>> wrote:
> 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 <mailto: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,
> Pedro Duque Vieira
More information about the openjfx-dev