B4J Question B4XView and ScrollPane LoadLayout

keirS

Well-Known Member
Licensed User
Longtime User
Cant seem to get LoadLayout to work. I can load a layout by casting back to a Scorllpane:
B4X:
 Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim JOMainForm As JavaObject
    
    Private scroller As B4XView
    Private displaypane As B4XView
    Private SP As ScrollPane
    Dim InnerPane As Pane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("scroller") 'Load the layout file.
    MainForm.Show
    JOMainForm = MainForm
    JOMainForm.GetFieldJO("stage").RunMethod("setMaximized", Array(True))
    
    SP = scroller
    SP.LoadLayout("Content",800,800)
    Log(scroller.ScrollViewInnerPanel)
    
    
    
End Sub

But loading the layout using B4XVIew crashes::

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("scroller") 'Load the layout file.
    MainForm.Show
    JOMainForm = MainForm
    JOMainForm.GetFieldJO("stage").RunMethod("setMaximized", Array(True))
    
'    SP = scroller
'    SP.LoadLayout("Content",800,800)
    Log(scroller.ScrollViewInnerPanel)
    scroller.LoadLayout("Content")
    
    
    
End Sub

causes: java.lang.ClassCastException: class javafx.scene.control.ScrollPane cannot be cast to class javafx.scene.layout.Pane (javafx.scene.control.ScrollPane is in module javafx.controls of loader 'app'; javafx.scene.layout.Pane is in module javafx.graphics of loader 'app')

Is casting the B4XView back to Scrollpane the correct way to this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Pay attention to B4XView methods documentation:

1593435433145.png


The solution is indeed to cast it to ScrollPane or keep it as ScrollPane.
 
Upvote 0
Top