B4J Question Getting started ...

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have done several projects with B4A. Now I am trying out B4J but I always have trouble getting started, partly because I don't usually use Layouts and I am trying to use them with B4J. This time I want to fill MainForm with a scrollable canvas. Here is my code ...

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("main")     ' Loads a scrollpane
    scrMain.LoadLayout("canvas", -1, -1)     ' Loads a canvas anchored to parent's extents
    ' Do something to see if this worked ...
    Dim p As Paint = fx.Colors.Green
    cvs.DrawCircle(200, 200, 200, p, True, 0)
    MainForm.Show
End Sub

This is the result ...

.

The canvas does not fill the scrollpane. In the Layout Designer the parent of the canvas is "Main", which is not what I want. But I can see another problem ahead when I want to extend the canvas beyond the scrollpane boundary. How should I be doing this?
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
when dealing with scrollpane you have an innerNode property.

B4X:
scrMain.innerNode
then you have prefWidth and prefHeight

B4X:
scrMain.innerNode.prefWidth = 700
scrMain.innerNode.prefWidth = 600
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Move the drawing in the MainForm_Resize routine.
In AppStart the dimensions of the view is not known.
Attached a modified version of your project.
What do you need the ScrollPane for, you don't set the dimensions of the InnerNode bigger than the ScrollPane view !?
 

Attachments

  • Project1.zip
    2.8 KB · Views: 165
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…