B4J Question Debugging desktop UI, B4J versus B4A

Didier99

Member
Licensed User
This is not really a question, more like a rant, so you can just skip if you are not in the mood :)

I have found that debugging UI issues is much easier on B4A than B4J because B4A executes UI calls immediately (like changing the color of a widget, or writing text into a label, or changing the property of a UI widget and reading it back) whereas B4J executes UI calls seemingly all at once when you leave the function where these calls are made, so you can't really single-step through the UI code in B4J to see what the code does like you can in B4A. I can use Sleep(0) statements to force a screen refresh, but that makes the routines resumable and complicates the overall flow, creating other issues.

I am working on a new B4J project at the moment that is fairly UI intensive (maybe a mistake on my part to implement the functionality the way I did) and I find that I spend a lot more time debugging those UI issues than I do on the functional code itself and it is frustrating. The amount of code reflects that as well, as there is much more code dealing with the UI than there is to implement the basic functionality. I hope that I am missing something and that there is a way to update the UI in real time without calling Sleep(0), at least when debugging.
 

Didier99

Member
Licensed User
Sure thing:

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private Button2 As Button
    Private label1, label2 As Label
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello World!", "B4X")
    label1.Text = "Label 1"
    label2.Text = "label 2"
End Sub

Sub Button2_Click
    label1.Text = ""
    label2.Text = ""
End Sub

and add to the form Button1, Label1, Label2 and Button2

If you put a break point on "xui.MsgboxAsync("Hello World!", "B4X")", click on Button1 and single step through the 3 lines under Button1_Click, the screen is not updated until you fall out of the function.

If you do the same thing under B4A, the screen is updated as you step through.
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
Any suggestion?
Not from me I'm afraid, other than to say that I hadn't noticed this behaviour before.
From the testing I've done, I don't think that the call to xui.MsgboxAsync makes any difference, the UI behaviour is the same with just:
B4X:
Sub Button1_Click
    label1.Text = "Label 1"
    label2.Text = "label 2"
End Sub
As @Didier99 said, the UI is not updated until the sub ends. I guess this is just the native UI behaviour.
Others might know better, but maybe the only solution would be the described use of sleep(0) to allow the UI to update.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I guess this is just the native UI behaviour.
I think so.
I am not sure how JavaFX works. Maybe it updates the UI process in an OS inside a loop or process queued by order and layer.
On Linux, we have something call display server like X11 or Wayland.
So an UI app will send message or make calls to the server and wait them be executed.
In Android I guess it is more simpler.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
A simple debugging way is to put some Log() lines inside the code to check the value at the time of execution.
 
Upvote 0
Top