B4J Question jReflection and SetEventHandler


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

See this simplified example:

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?



Well-Known Member
Licensed User
Longtime User

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.


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.

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?

Upvote 0