B4J Question LoadLayout

Daestrum

Expert
Licensed User
Longtime User
Not sure if its me misunderstanding the usage of LoadLayout, but here comes the explanation of the problem I have.

I have a project that has basically one main screen, into that I load various layouts depending on user interaction. As some screens need more space than others, I dynamically change the main screen size, and restore it when I leave the screen.

I have a routine which handles the saving and restore of the screen size title etc.

In Main class file I use
B4X:
Public Sub Initialize
    m = Main.MainForm
    WindowHandler.saveWindow(m)
    WindowHandler.newWindowLayout(m,350,400,"Log In2","loginScreen")
    Dim fred As String = "loginScreen" 
    m.RootPane.LoadLayout(fred)
    m.Show
End Sub
and all works as expected.

In the WindowHandler class I use this:
B4X:
Public Sub newWindowLayout(m As Form,h As Double,w As Double,t As String,lout As String)
    Log("new window")
    m.RootPane.RemoveAllNodes
    m.WindowHeight = h
    m.WindowWidth = w
    m.Title = t
    'm.RootPane.LoadLayout(lout)            ' <<<<<< this wont work, produces exception
End Sub
The height width title all get set correctly.

Sorry for long post - been trying for ages to discover why one works and one causes exception.
 

stevel05

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm,New As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show
    New.Initialize("Test",400,300)
    newWindowLayout(New,300,400,"New Form","2")
    New.Show
End Sub
Public Sub newWindowLayout(m As Form,h As Double,w As Double,t As String,lout As String)
    Log("new window")
    m.RootPane.RemoveAllNodes
    m.WindowHeight = h
    m.WindowWidth = w
    m.Title = t
    m.RootPane.LoadLayout(lout)            ' <<<<<< this wont work, produces exception
End Sub
It works for me, what exception are you getting?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Sorry for delay.
Here is the project zip (some classes are empty at present)
 

Attachments

  • GFlyer.zip
    3.5 KB · Views: 416
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Thank you Erel for the reply.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Finally I understand, couldn't understand why something I can do so easilyy in pure Java was giving me such a problem.
I was over thinking the problem, trying to do too much, when B4J would do it for me.

Maybe this tiny example will help others understand. It just provides a way of traversing screens forward and back.
 

Attachments

  • FinallySorted.zip
    3.3 KB · Views: 439
Upvote 0

manios

Active Member
Licensed User
Longtime User
While testing I get the following error:
B4X:
Parsing code.                          0.00
Compiling code.                        0.05
Compiling debugger engine code.        Error
javac 1.7.0_45
shell\src\finally\sorted\loginscreen.java:2: error: <identifier> expected
package finally.sorted;
      ^
1 error
Any idea where to look?
Other testprograms compile OK
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
While testing I get the following error:
B4X:
Parsing code.                          0.00
Compiling code.                        0.05
Compiling debugger engine code.        Error
javac 1.7.0_45
shell\src\finally\sorted\loginscreen.java:2: error: <identifier> expected
package finally.sorted;
      ^
1 error
Any idea where to look?
Other testprograms compile OK
Just change the package name - I changed it to 'finally.sorted' which it doesn't like. Sorry.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I think was either b4a.example or b4j.example originally
 
Upvote 0
Top