B4J Question Perform click

ThRuST

Well-Known Member
Licensed User
Longtime User
This code is for Android, but how to do this in B4J?

Usage
Code: Copy
SimulateClick(BtnTest1)

Code
Code: Copy
Public Sub SimulateClick(b As Button)
    Dim r As Reflector
    r.Target = b
    r.RunMethod("fire")
End Sub

Attached is the solution source code example. Thanks to Daestrum for the B4J solution.
 

Attachments

Last edited:
Just change the RunMethod from "performClick" to "fire"

(Works on buttons not tested on anything else)
 
Upvote 0
It seems impossible to set focus to the form once it scrolls up from the bottom of the screen and stops like on the screenshot.
I've placed a dummy button called BtnFocusButton on the form just to try various methods without success.
What is needed is a virtual click on the form since it stays on toop of the traybar once I click on it. I want it to stay on top of the traybar every time it scrolls up.
I tried your code that sets focus to the HTMLeditor webview but it generated an error about child components. I could just call button and label not form.
AlwaysOnTop and RequestFocus is not enough. I guess you can simulate this with a form that activates a timer to set the form on top and before that click the traybar
to give it focus then have the timer automatically set the focus to the form. All my efforts has been fruitless. It might have something to do with the SetFocusTraversable.

Attaching screenshot (notice the traybar at the bottom)

Capture.JPG
 
Upvote 0
When I click on the form it looks like this (which is the way I want it to always be)

Capture.JPG
 
Upvote 0
Parts of the code in an infinite timer loop

Code: Copy
    ' Stop panel
    If TmrPanelUp.Enabled = True And MainForm.WindowTop <= primaryHeight - 400 Then
    
    ' Stop scrolling upwards
    TmrPanelUp.Enabled = False
    
    'Sleep(0)
    'SimulateClick(BtnFocusButton)
    'Sleep(0)
    ' Set always on top
    MainForm.AlwaysOnTop = True
    MainForm.RootPane.RequestFocus
    BtnFocusButton_Click
    
    ' Set flag
    PanelIsUp = True
    
        
    End If


Tested this before (without success)

Code: Copy
public Sub SetFocus(Obj As Button)
        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
 
Upvote 0
It should be enough that the form is set AlwaysonTop = True. See the attached example. You only need to set it once when the app starts, unless you want to toggle it.
 

Attachments

Upvote 0
@Steve05 Thanks, and nice example. I've made some changes to your example to illustrate the problem. Take a look at it and see if you can solve :)
 

Attachments

Upvote 0
You are fighting against operating system behaviour and guess who will win :). The best you can do is to start the form at the front, if the user doesn't click the bottom bar then it will stay there. See attached.

As your app covers the whole bottom bar, it is unlikely that it will get clicked in between the animation starting and the form covering the bottom bar.
 

Attachments

Upvote 0
Hahaha :) Steve that was funny and how provoking to see you come up with a solution when this has been a brain scratcher for many month.
And yes my project is a rebellic effort against both Microsoft and Apple. I must test this code and see if it is compatible with the Macintosh,
or else Steve Jobs will awaken from his grave and be knocking at your door every night :D
Btw I was about to make a donation to you earlier but I didn't want to give away my code so I'll have to look for another way.
Or you can wait untill Athena goes worldwide to 100 million computers and I'll send you a postcard with a check... haha :eek:
 
Upvote 0
YOOOHOOO STEVE IT WORKS :-))))) I Added it in my project and it works like a dream. PERFECT.

Damn you're good Steve. Best of the Best.

It's poetry in motion to see this solved. Oh my oh my what a moment of nirvana haha :)
 
Upvote 0
And here it is, that magic code. Provided by MASTER STEVE

Code: Copy
Sub FormToFront
    
    'Send the window to the front before it's shown.
    Dim Stage As JavaObject
    Dim FormJO As JavaObject = MainForm
    Stage =  FormJO.GetField("stage")
    Stage.RunMethod("toFront",Null)
    
End Sub

Now my soul will rest in peace in all eternity :)
 
Upvote 0
Now my soul will rest in peace
GOT to love it when it all comes together - with the kindness and expert insight of others who see what we cannot in our time of need.
Always amazes me how intelligent others are - when you ask the right / properly phrased question.

Again - is there anything we CAN'T accomplish here (B4X) when (some of) 100 G plus users put some thought to it? (along with our good friend - JavaObject - and those who know it...)
 
Upvote 0
@Harris You're right. There will always be someone smarter than yourself. That's the beauty of life when everyone cares to help eachother instead of sending rockets and bombs. The moment you realize that knowledge and vision can be united, that's when the journey towards a better life begins. Programming is a one hard road, but once code works it's worth every effort of the time and frustration put into it. Luckily we all know this, that's what makes B4X so great. It's not just the language, it's the people and minds behind it. That makes Erel the new King David of Israel. Blessed are our souls to be an apprentice of a powerful huge knowledge. The art of programming :)
 
Upvote 0
As web technologies evolve, it is impossible for one single individual to keep up with everything. This is the main reason why I develope Athena. It will be the best of applications. In fact one of the most important applications ever created and it's the fruit of life-long studies and a great cooperation between some of the best programmers in this forum. Ladies and gentleman, I therefor present you Athena. It's the tool that will be useful for everybody, and if Steve Jobs had still been around he would of course be using it since it's a knowledge framwork. It's the closest thing to a knowledge implant to the brain, but software driven. This is a sneakpeak, and like apple, Duologic Software will keep working to offer you the one of the top 10 applications ever created. It's your best friend, your teacher, your slave, your everything. You can handle every task with a computer and will change the way users interact with a computer system. The floating menu can be programmed to handle everything. Here's a screenshot.

Capture2.JPG


Capture.JPG
 
  • Like
Reactions: udg
Upvote 0
@ThRuST : you surely know how to sell :)
 
Upvote 0
As web technologies evolve, it is impossible for one single individual to keep up with everything. This is the main reason why I develope Athena. It will be the best of applications. In fact one of the most important applications ever created and it's the fruit of life-long studies and a great cooperation between some of the best programmers in this forum. Ladies and gentleman, I therefor present you Athena. It's the tool that will be useful for everybody, and if Steve Jobs had still been around he would of course be using it since it's a knowledge framwork. It's the closest thing to a knowledge implant to the brain, but software driven. This is a sneakpeak, and like apple, Duologic Software will keep working to offer you the one of the top 10 applications ever created. It's your best friend, your teacher, your slave, your everything. You can handle every task with a computer and will change the way users interact with a computer system. The floating menu can be programmed to handle everything. Here's a screenshot.

View attachment 67537

View attachment 67538
Can you know exactly what to do?

Do you develop programs for me?
 
Upvote 0
Back
Top