B4J Question Set focus on control

ThRuST

Well-Known Member
Licensed User
Longtime User
I want to get my application to get focus to be set on top of the Windows Traybar. Unfortunatelly RequestFocus and AlwaysOnTop is not enough when I click the traybar and my program (Athena) is called and scrolls up from mouse movement. I want it to always be on top of the traybar at the bottom of the screen. The idea is to set focus to the forma button or a label since it works when I click on the panel.
The idea is to simulate a click event at the moment the mouse cursor reaches the bottom of the screen.


I have this code which needs to be modified to be used with any control. Currently it gives the error about child components. Can any of you experts please made this code work, or come up with another solution since perform click is not enough.

I have this code by Erel (it was used to set focus to the HTMLeditor webview)

B4X:
public Sub SetFocus(Obj As HTMLEditor)
    
    Dim jo As JavaObject = Obj
    Dim wv As JavaObject = jo.RunMethodJO("getSkin", Null).RunMethodJO("getChildren", Null) _
       .RunMethodJO("get", Array(0)).RunMethodJO("getChildren", Null).RunMethod("get", Array(2))
    Sleep(500)
    Dim mevent As JavaObject
    Dim meventstatic As JavaObject
    meventstatic.InitializeStatic("javafx.scene.input.MouseEvent")
    mevent.InitializeNewInstance("javafx.scene.input.MouseEvent", _
       Array(meventstatic.GetField("MOUSE_PRESSED"), 100.1, 100.1, 200.1, 200.1, "PRIMARY", 1, False, False, False, False, False, False, False, False, False, False, Null))
    wv.RunMethod("fireEvent", Array(mevent))
    Obj.RequestFocus
    mevent.InitializeNewInstance("javafx.scene.input.MouseEvent", _
       Array(meventstatic.GetField("MOUSE_RELEASED"), 100.1, 100.1, 200.1, 200.1, "PRIMARY", 1, False, False, False, False, False, False, False, False, False, False, Null))
    wv.RunMethod("fireEvent", Array(mevent))
    
End Sub
 

stevel05

Expert
Licensed User
Longtime User
You can set an Eventfilter using the Reflection Library.
 
Upvote 0
Top