B4J Question [SOLVED] ScrollPane question - items not visible

Discussion in 'B4J Questions' started by HowardTheDuck, Oct 12, 2019 at 10:07 PM.

  1. HowardTheDuck

    HowardTheDuck Member Licensed User

    Hi, I'm trying to populate a ScrollPane with canvases that each have something different drawn on them, like the example below. I'm initializing a canvas, drawing a rectangle on it, then adding it to the scrollpane.

    The rectangles are not visible; what am I doing wrong?

    Code:
    #Region Project Attributes
        
    #MainFormWidth: 600
        
    #MainFormHeight: 600
    #End Region

    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
        
    Private ScrollPane1 As ScrollPane
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.RootPane.LoadLayout(
    "Main"'Load the layout file.
        MainForm.Show
      
        AppInit
    End Sub

    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub

    Sub AppInit
        ScrollPane1.SetVScrollVisibility(
    "NEVER")
        ScrollPane1.LoadLayout(
    "ScrollPane.bjl",0,0)
        
    Dim n As Pane = ScrollPane1.InnerNode
        
    For i = 0 To 100
            
    Dim cvs As Canvas
            cvs.Initialize(
    "cvs")
            cvs.DrawRect(
    0,0,20,i,fx.Colors.Cyan,True,0)
            n.AddNode(cvs,i*
    20,0,-1,-1)
        
    Next
        n.PrefWidth = (i*
    20) + 20
    End Sub
    The "Main" layout file simply contains the ScrollPane ScrollPane1 and nothing more. The ScrollPane.bjl file is blank.


    EDIT: My end goal is to create a bar graph which might be wider that the program window, so some type of scrolling is required. If someone has another idea as to how I might accomplish that with a different method I would be interested in hearing it.
     
    Last edited: Oct 13, 2019 at 2:05 AM
  2. HowardTheDuck

    HowardTheDuck Member Licensed User

    It seems as though I need to add the scrollpane in the code rather than with the designer; also, I didn't have the canvas height and width set.

    Code:
    #Region Project Attributes
        
    #MainFormWidth: 600
        
    #MainFormHeight: 600
    #End Region

    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.RootPane.LoadLayout(
    "Main"'Load the layout file.
        MainForm.Show
        
        AppInit
    End Sub

    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub

    Sub AppInit
        
    Dim ScrollPane1 As ScrollPane
        ScrollPane1.Initialize(
    "ScrollPane1")
        MainForm.RootPane.AddNode(ScrollPane1,
    50,200,300,150)
        
        ScrollPane1.SetVScrollVisibility(
    "NEVER")
        ScrollPane1.SetHScrollVisibility(
    "ALWAYS")
        
    Dim n As Pane
        n.Initialize(
    "n")
        
        ScrollPane1.InnerNode = n
        ScrollPane1.InnerNode.SetSize(
    2000,150)
        
        
    For i = 0 To 100
            
    Dim cvs As Canvas
            cvs.Initialize(
    "cvs")
            cvs.Height = 
    150
            cvs.Width = 
    20
            cvs.DrawRect(
    0,0,20,i,fx.Colors.Cyan,True,0)
            n.AddNode(cvs,i*
    20,0,20,150)
        
    Next
        n.PrefWidth = (i*
    20) + 20'Adjust the height of the innernode pane
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice