B4J Question How to make a window "top most" (Solved-JFX8)

jmon

Well-Known Member
Licensed User
Hello,

I would like to have a window always on top of all the other desktop windows. "System top most". Is it possible with B4J? I have the feeling that it's the stage/toFront() from this page, but I don't know how to implement it in B4J.

Thanks.

[edit] : See the solution on post #10
 
Last edited:

jmon

Well-Known Member
Licensed User
ok, so if I understand correctly, for the moment it's not possible to have the owner in background and the child above all other desktop windows?

Argh.. I will have to wait for a few months!

Thanks
 

Gary Miyakawa

Active Member
Licensed User
Is there any way for a form to be on top of ALL other windows ? (like, on Visual Basic, form.topmost)

I found a piece of code but don't know how to implement it on B4J...

B4X:
stage.initModality(Modality.APPLICATION_MODAL);
Any help would be appreciated !

Gary M
 

jmon

Well-Known Member
Licensed User

swissmade

Well-Known Member
Licensed User
Hi all,
Maybe a sample of this how it is done.
Many thanks for help.;)
 

jmon

Well-Known Member
Licensed User
Hi all,
Maybe a sample of this how it is done.
Many thanks for help.;)
Here:
B4X:
setAlwaysOnTop(Form, True)

Sub setAlwaysOnTop(frm As Object, Value As Boolean)
    Dim frmJO As JavaObject = frm
    Dim stage As JavaObject = frmJO.GetField("stage")
    stage.RunMethod("setAlwaysOnTop", Array(Value))
End Sub
 

swissmade

Well-Known Member
Licensed User
Here:
B4X:
setAlwaysOnTop(Form, True)

Sub setAlwaysOnTop(frm As Object, Value As Boolean)
    Dim frmJO As JavaObject = frm
    Dim stage As JavaObject = frmJO.GetField("stage")
    stage.RunMethod("setAlwaysOnTop", Array(Value))
End Sub
Nice working.
Many thanks for this you are a live saver ;);)
 
Last edited:

JTmartins

Active Member
Licensed User
Works Perfectly, however it interferes with jMsgBoxes, as they apear underneath.

The trick is to do this everytime there is a msgbox to apear

B4X:
setAlwaysOnTop(MainForm, False)
Msgbox.Show("blah blah blah", "testing")
setAlwaysOnTop(MainForm, True)
So before we call the msgbox we disable the always on top, show the msgbox and after that we enable again the always on top.
 
Last edited:

ivanomonti

Well-Known Member
Licensed User
Error function!!! I need to have a window always on top, I used the following code, but by mistake

B4X:
setAlwaysOnTop(FormEdit, True)
B4X:
Sub setAlwaysOnTop(frm As Object, Value As Boolean)
    Dim frmJO As JavaObject = frm
    Dim stage As JavaObject = frmJO.GetField("stage")
    stage.RunMethod("setAlwaysOnTop", Array(Value))
End Sub
B4X:
Program started.
Error occurred on line: 124 (cssmodule).
java.lang.RuntimeException: Method: setAlwaysOnTop not found in: javafx.stage.Stage
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:367)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:606)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:227)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
    at anywheresoftware.b4a.BA$2.run(BA.java:165)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)
 
Top