B4J Question ScrollPane missing GetAllViewsRecursive

Cableguy

Expert
Licensed User
Longtime User
Hi guys,

Any way I can get anything that can resemble the rootpane.getallviewsrecursive for a scrollpane?
 

LucaMs

Expert
Licensed User
Longtime User
I was thinking (given that I don't know that "rootpane") that probably it is like the B4A ScrollView, then you should use the "same method": get the internal panel and apply GetAllViewsRecursive to it.

I was testing when...

B4X:
If sp.InnerNode = Null Then
        Log("is null")
    Else
        Log("is NOT null")
    End If
 
    Log(GetType(sp.InnerNode))

sp is an empty ScrollPane, but the first log writes "is NOT null", the second raises an error because... InnerNode is not initialized! :eek:

Well, the method should be that, I suppose.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
rootpane is the anchor pane of the MainForm, and it has a getallviewsrecursive, but, scrollpane method, wich is also an achor pane, does not have such a method, thou we can load a layout to it... so I need to find a way to get the scrollpane child nodes (views)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
yes, I saw that one after your last reply, but I'm getting an error just by adding the dim line!

B4X:
Program started.
main._initializeandbuildmaps (java line: 119)
java.lang.RuntimeException: Object should first be initialized (Node).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
    at b4j.example.main._initializeandbuildmaps(main.java:119)
    at b4j.example.main._openlayout_action(main.java:153)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA$2.run(BA.java:165)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Does this help - it is how I understand to work with the ScrollPane - Have tested below and is working fine.

'1. Define the scrollpane
B4X:
Dim sp As ScrollPane
sp.Initialize("sp")
sp.SetVScrollVisibility("ALWAYS")
sp.Pannable = True

'2. Define a Pane which gets the ScrollPane InnerNode Assigned
B4X:
Dim pn As Pane = sp.InnerNode

'3. Add Views to the Pane defined
B4X:
Dim btn As Button
btn.Initialize("btn")
btn.Text = "Button " & i
btn.Tag = "button" & i
pn.AddNode(btn,...)
... add more Views

'4. Add the ScrollPane to the RootPane
B4X:
MainForm.RootPane.AddNode(sp, 0, 0, MainForm.Width/3, MainForm.Height)

'5. To get the Views defined loop over the Pane
B4X:
For Each n As Node In pn.GetAllViewsRecursive
   Log(n.Tag)
Next
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi rob, my issue is, I think, that I added my scrollpane with the designer thus its not letting me initializing it in the code
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The simplest way to fill a ScrollPane is by calling ScrollPane.LoadLayout. This will create a Pane, set it as the inner node and load the layout file to this pane.

Later you can iterate over the views with:
B4X:
Dim p As Pane = ScrollPane1.InnerNode
For Each n As Node in p.GetAllViewsRecursive

Next
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi, Paulo,

have you found the solution?

Is this a small bug of b4j?
Hi Luca, I haven't been able to test any further, its been a hard week and not much time to code, but Erel has shed some light on the subject in his last post.
 
Upvote 0
Top