B4J Question force a view to visually refresh NOW

a n g l o

Active Member
Licensed User
Longtime User
hello
an example is attached.
as you can see - the list is VISUALLY populated ONLY AFTER the loop is finished.
i must have it VISUALLY populated when it's actually populated (right after the 'add' command).

in vb and even in b4A a DoEvents (every x mod y=0) makes it.

no DoEvents in b4J, i've tried the callSubDelayed + a timer combination.
well, it seems (to me) that there must be a compatibility between the timer interval and the loop speed.
that's of course varies between machines (and even in same machine, other time).
that ain't enough accurate for me.
i need it to behave exactly as if i put a log command and see it in the log pane in real time.

is there a way to force the control to VISUALLY refresh NOW ?

Thank you
 

Attachments

  • viewUpdate.zip
    13.3 KB · Views: 232

rboeck

Well-Known Member
Licensed User
Longtime User
I have a situation, where i place tree tableviews on one page - the third needs some seconds to calculate.
I had tried for hours, to show the first two tables to the users, which only needed 100 ms to calculate and show, but on some machines the "system" is waiting for the last view.
They only possibility i found, was the use of CallSubDelayedPlus; but even there i had to make 500 ms time difference between the views to get the image of the first two views. With smaller delays i get the waiting effect back.
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
DoEvents is almost never the correct solution.
Do you really want to update the layout after each iteration (there are 1 million items)? It will be very slow and the user will only see the first few items anyway.
You can use a timer and add a few items every tick.

Erel, thank you
first, the 1 million is only in the example to "feel" the issue..
second, as i wrote in the Q, there's the log pane of the IDE. if you replace the 2 lines dealing with the ListView with : log(i),
- I 'd like to get the same behavior/effect as in the IDE log pane. i see there the million running in real time.

if you made it in the IDE, you surly know how to b4j it as well (w/o timer) ..:)

Thanks
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
........

In this case you can load the first 20 items with a fast timer and then load all the other items which are not visible anyway.

you write that for the 2nd time (all others not visible anyway).
you must have missed the line in the loop in which in each iteration the list scrolls down to last entry.

ok. i've got the msg clear (impossible w/o timer, pretty lame with timer).

if my poor opinion worth something - i see it as a real and sometimes critical drawback.
it is not acceptable that the UI will not be easily updated during loops.
i've read here your post about promoting b4j as RAD tool.
well, i'm still running vb6 IDE on win10-64bit with no problems (including package & deployment wizard...),
and there, there are no such UI update problems as i find in b4j.

if there's a solution that may slows the loop (DoEvents) - i say : let the developer decide if and how to use it.

i know nothing of Java. may i ask why you've inserted DoEvents in b4a but not in b4j ?

thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why is it lame with a timer? Can you post an example?

Sounds to me that it should work better with a timer as you control the timing. What is the purpose of letting it update the list as fast as possible? The speed will be completely dependent on the specific computer.

i know nothing of Java. may i ask why you've inserted DoEvents in b4a but not in b4j ?
It is technically not possible to implement DoEvents in the JavaFX framework.

DoEvents had it place in B4A when B4A was less mature. Now there are almost no cases where it is the "correct solution". For example if you need to issue many SQL queries then you should use the asynchronous SQL methods. Such methods were not available in the past.

It causes more issues (crashes) than one might expect and it should be avoided. A warning will be shown for DoEvents usage in the future.
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
Why is it lame with a timer? Can you post an example?

Sounds to me that it should work better with a timer as you control the timing. What is the purpose of letting it update the list as fast as possible? The speed will be completely dependent on the specific computer.

that's was just an examlpe...what's lead to it is a project in which there are only 10-100 iteration of the loop that each can take 1-4 seconds (depending on the computer).
if i put the timer to 1 sec - on some computers many tick events will be fired for nothing. if i put it for 4 seconds, on some (other) computers i'll get a flush of 4 lines update at once. the loop is slow and the lines for the list are full of info, my goal is that the user can read each line at ease.

so you see - it's not accurate, and have to be aimed to common factor which is too large (fastest timer that'll be fired many times for nothing (what i did and don't like)).

i need to control the event (of adding to list) and not the timing.

Thanks anyway for your time.
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
PS
i forgot to ask about 1 more point :
from inside the above loop, there's no problem to change the MainForm Title and see the change in real time.
what's the different between the form title and controls on the form pane itself ?
does the form title belongs to other thread ?
Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
does the form title belongs to other thread ?
No.

what's the different between the form title and controls on the form pane itself ?
The nodes tree requires a full layout to redraw itself while the title doesn't.

Almost all UI features will only be updated when the main thread is free to process the message queue.
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
Thank you !
"Almost all" is better the "all"....
if you know about a control that makes the "almost", please let know
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Running your example code with 1m entries (with a few tweaks) results in the listview being populated and displayed in 23ms. Surely this is fast enough for your users.

The tweaks I used were:
a, Don't add individual items to the listview, add them to a List and then either
add to the listview in one hit(addall)
or
tell the listview to use the list for its data (setItems - needs javaobject)

b, Don't use scrollto after every addition, it has a killer overhead. You can find out how many items are in listview, just scrollto it afterwards.

Hope this helps you speed up your listview display.
(I can show you full code to speed up listview display if required - uses pure java)
 
Upvote 0
Top