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?
 
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...

Code: Copy
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
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
yes, I saw that one after your last reply, but I'm getting an error just by adding the dim line!

Code: Copy
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
Does this help - it is how I understand to work with the ScrollPane - Have tested below and is working fine.

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

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

'3. Add Views to the Pane defined
Code: Copy
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
Code: Copy
MainForm.RootPane.AddNode(sp, 0, 0, MainForm.Width/3, MainForm.Height)

'5. To get the Views defined loop over the Pane
Code: Copy
For Each n As Node In pn.GetAllViewsRecursive
   Log(n.Tag)
Next
 
Upvote 0
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
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:
Code: Copy
Dim p As Pane = ScrollPane1.InnerNode
For Each n As Node in p.GetAllViewsRecursive

Next
 
Upvote 0
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
Back
Top