B4J Question scrollpane headache.

Discussion in 'B4J Questions' started by gruizelgruis, Jan 5, 2016.

  1. gruizelgruis

    gruizelgruis Member Licensed User

    Hello all.

    After finishing my B4a app. I am looking into B4J to create a new application.

    I like to create a hospitality table reservation program. It should have the same layout as google calander. With names on the Y-ax and time on the x-ax. And be able to scroll in both directions.

    I have been trying to get my head around this scrollpane, but i'm pulling my hair out at this point.

    I like to add an object (button / label or "pane with a layout") to the scrollpane.
    This object has a fixed hight and a variable width. At a fixed starting point.

    The scrollpane must be able to scroll in both directions.

    Is there an example i can use ?
    is there a better way/object to use ?

    Here is a bit off code i'm strugeling with. It should add a button at the clicked position.


    Code:
    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
       
        
    Dim Sp As ScrollPane
        
    Dim pnl As Pane
       
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
       
        MainForm = Form1
        MainForm.SetFormStyle(
    "UNIFIED")
        MainForm.RootPane.LoadLayout(
    "LT1"'Load the layout file.
        MainForm.Show
          
        Sp.Initialize(
    "Sp"'// the scrollpanel as created on the layout "LT1"
       
        pnl = Sp.InnerNode  
    '// A pane as an innernode ? ( i assume its a panel inside a scrollpanel)
        pnl.Initialize("Pnl")
       
    End Sub


    Sub pn_MouseClicked (EventData As MouseEvent)

        
    Dim CmdReservering As Button 
       
        CmdReservering.Initialize(
    "CmdReservering")

        pnl.AddNode(CmdReservering,EventData.X,EventData.y,
    100dip,100dip)

    End Sub

    Please advice.
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    Hi,
    usually you will load a layout into your scrollpane, something like this:
    Code:
    sp.LoadLayout("myLayout", -1800)
        
    'and set the scroll visibility
        sp.SetVScrollVisibility("AS_NEEDED")
        sp.SetHScrollVisibility(
    "NEVER")
    in this case a layout (with buttons, webviews and whatever...) will be loaded into the scrollpane with a width which will fit (=-1) and a hight of let's say 800.
    Then the scroll visibility will be set to horizontal never - because it fits - and verticaly as needed.

    hope this helps a bit...if not, may be aspirin will help;)
     
  3. gruizelgruis

    gruizelgruis Member Licensed User

    Thank you for your quick responce.
    I sure will try this to get a better feel for scrollpane.
    But I do need to be able to add/remove items. I dont think that can be done with a "layout"
     
  4. eurojam

    eurojam Well-Known Member Licensed User

    May be this goes more in that direction:

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

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.SetFormStyle(
    "UNIFIED")
        
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
       
        
    Dim sp As ScrollPane
        sp.Initialize(
    "Scrollpane")
        MainForm.RootPane.AddNode( sp,
    0,0,MainForm.Width,MainForm.Height)

        sp.SetVScrollVisibility(
    "ALWAYS")
        sp.SetHScrollVisibility(
    "ALWAYS")   
        
    Dim p As Pane
        p.Initialize(
    "p")
      
        sp.InnerNode = p
        sp.InnerNode.SetSize(
    1000,1000)
       

        
    For i = 0 To 5
          
    Dim b As Button
          b.Initialize(
    "b")
          p.AddNode(b,
    100*i,100*i,100,100)
        
    Next
       
        MainForm.Show
    End Sub
     
    HowardTheDuck and An Schi like this.
  5. gruizelgruis

    gruizelgruis Member Licensed User

    Super!.. thanks.
    For some reason it does not allow this with a pre-defined scrollpane on a layout.
    And i feel it has to do with the

    Code:
    sp.Initialize("Scrollpane")
    When using a layout, the initialization is not needed.
    But this
    Code:
    Dim p AsPane
     p.Initialize(
    "p")
     
     sp.InnerNode = p
    Bit needs the scrollpane to be initialization first.

    So when initializing a scrollpane that exists on a layout seems to lose its connection to the code.
    And the whole thing does not work.

    Just my 2 cents

    Thanks again.
     
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