B4J Question jReflection and SetEventHandler

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
In B4J I would like to use the cursor keys to change the position of Panes.

See this simplified example:
https://www.b4x.com/android/forum/threads/draw-rectangular-windows-on-image.48961/#post-305781

I'm using jReflection and AddEventHandler. The problem arises when I have other controls on the form. They capture or respond to the keypress most likely before I have a chance to consume the event.

I've tried AddEventHandler, AddEventFilter, both with and without the E.consume. In every case the control that has the focus receives the key event before I get a chance process it - I hit the arrow keys and the tab changes or the next button gets selected no matter what I do.

There is another method "SetEventHandler" which is not exposed in jReflection. This method says it guarantees to be first in line. It appears to be what I want.

Is there a way to set this event handler?
Am I barking up the wrong tree and this method will accomplish what I want?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks.

I've tried to find more confirmation that SetEventHandler will, in fact, do what I'm looking for. After quite a few Google searches all I found was the Java documentation.

http://docs.oracle.com/javase/8/jav...fx.event.EventType-javafx.event.EventHandler-

addEventHandler
Registers an event handler to this node. The handler is called when the node receives an Event of the specified type during the bubbling phase of event delivery.

setEventHandler
Sets the handler to use for this event type. There can only be one such handler specified at a time. This handler is guaranteed to be called first. This is used for registering the user-defined onFoo event handlers.

Documentation for other Java related environments does confirm, for those environments, that "Set" version will completely take over handling the event.

I know of no way to find out if this will work other than to test it.

I am surprised SetEventHandler is not exposed in jReflection. Have you tried using the "Set" version of this function?

I believe agraham makes the comment that JavaObject can accomplish similar things.

Is it possible to do this with JavaObject?

Barry.
 
Upvote 0
Top