B4J Code Snippet ScrollPane helper code module

Discussion in 'B4J Code Snippets' started by knutf, Apr 22, 2019.

  1. knutf

    knutf Member Licensed User

    Maybe this helper subs can be helpful for useing ScrollPane. They depend on JavaObject library.
    Code:
    'Static code module
    Sub Process_Globals
        
    'Private fx As JFX
        Public const AS_NEEDED  As String = "AS_NEEDED"
        
    Public const ALWAYS  As String = "ALWAYS"
        
    Public const NEVER  As String = "NEVER"
    End Sub

    'Return true if the Vertical Scrollbar is visible on the given ScrollPane
    Public Sub getVbarVisible(SP As ScrollPaneAs Boolean
        
    Select Case getVbarPolicy(SP)
            
    Case ALWAYS
                
    Return True
            
    Case NEVER
                
    Return False
            
    Case Else 'AS_NEEDED
                If SP.InnerNode.IsInitialized  = False Then
                    
    Return False
                
    Else If SP.FitToHeight = True Then
                    
    Return False
                
    else if SP.InnerNode.PrefHeight > getViewportHeight(SP) Then
                    
    Return True
                
    Else
                    
    Return False
                
    End If
        
    End Select
    End Sub

    'Return true if the Horizontal Scrollbar is visible on the given ScrollPane
    Public Sub getHbarVisible(SP As ScrollPaneAs Boolean
        
    Select Case getHbarPolicy(SP)
            
    Case ALWAYS
                
    Return True
            
    Case NEVER
                
    Return False
            
    Case Else 'AS_NEEDED
                If SP.InnerNode.IsInitialized  = False Then
                    
    Return False
                
    Else If SP.FitToWidth = True Then
                    
    Return False
                
    else if SP.InnerNode.PrefWidth > getViewportWidth(SP) Then
                    
    Return True
                
    Else
                    
    Return False
                
    End If
        
    End Select
    End Sub

    'Return the height of the Viewport of the given ScrollPane
    Public Sub getViewportHeight(SP As ScrollPaneAs Double
        
    Dim SPJO As JavaObject = SP
        
    Return SPJO.RunMethodJO("getViewportBounds",Null).RunMethod("getHeight",Null)
    End Sub

    'Return the width of the Viewport of the given ScrollPane
    Public Sub getViewportWidth(SP As ScrollPaneAs Double
        
    Dim SPJO As JavaObject = SP
        
    Return SPJO.RunMethodJO("getViewportBounds",Null).RunMethod("getWidth",Null)
    End Sub

    'Return the policy of the vertical ScrollBar of the given ScrollPane.
    'The policy is "AS_NEEDED", "ALWAYS" or "NEVER"
    Public Sub getVbarPolicy(SP As ScrollPaneAs String
        
    Dim SPJO As JavaObject = SP
        
    Return SPJO.RunMethod("getVbarPolicy",Null)
    End Sub

    'Return the policy of the horizontal ScrollBar of the given ScrollPane.
    'The policy is "AS_NEEDED", "ALWAYS" or "NEVER"
    Public Sub getHbarPolicy(SP As ScrollPaneAs String
        
    Dim SPJO As JavaObject = SP
        
    Return SPJO.RunMethod("getHbarPolicy",Null)
    End Sub

    Public Sub getInnerNodeActualHeight(SP As ScrollPaneAs Double
        
    Dim INJO As JavaObject = SP.InnerNode
        
    Return INJO.RunMethod("getHeight",Null)
    End Sub

    Public Sub getInnerNodeActualWidth(SP As ScrollPaneAs Double
        
    Dim INJO As JavaObject = SP.InnerNode
        
    Return INJO.RunMethod("getWidth",Null)
    End Sub
     
    Johan Hormaza and ilan like this.
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