B4J Question Keep forms on top and swap focus

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I have a main form which is loaded and occupies the whole screen.
I load another form loaded from a code module which opens on top of the main form on the right half of the screen and needs to stay on top so I use form.showandwait in the 2nd module.

My problem is I need to move focus back to the main form to scroll thru a table view but keep the 2nd form open and on top then move focus back to the second form.

If I just use form.show the 2nd form disappears behind the main form but I need keep it on top.

Its not a problem if both forms are in the same code module but I have multiple popup forms that need to switch focus between itself and the main form.

Hope this is clear as mud.....

Any ideas?
 

atiaust

Active Member
Licensed User
Longtime User
Thanks Erel,

This woks as long as you set "Private Mainform as Form" to Public

If you close the second form and try to open it again I get an error:

Error occurred on line: 21 (RightForm)
java.lang.IllegalStateException: Cannot set owner once stage has been set visible
at javafx.stage.Stage.initOwner(Stage.java:561)
at anywheresoftware.b4j.objects.Form.SetOwner(Form.java:222)
at b4j.example.rightform._show(rightform.java:63)
at b4j.example.main._btnright_mouseclicked(main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


Any ideas ?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This may help
B4X:
...
AlwaysOnTop(MainForm,True) ' this could be any form
End Sub

private Sub getStage(o As JavaObject) As JavaObject
Return o.GetFieldJO("stage")
End Sub
Sub AlwaysOnTop(o As Form,boo As Boolean)
getStage(o).RunMethod("setAlwaysOnTop",Array(boo))
End Sub
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thanks Erel.
When you close the second form using "form.close" does it not actually remove the form?
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
My apologies to Daestrum,

I meant to thank you for your reply. I did try your suggestion but by the time I got back to the issue Erel had replied as well.

Thanks
 
Upvote 0
Top