B4J Code Snippet ScrollPane helper code module

knutf

Member
Licensed User
Maybe this helper subs can be helpful for useing ScrollPane. They depend on JavaObject library.
B4X:
'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 ScrollPane) As 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 ScrollPane) As 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 ScrollPane) As 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 ScrollPane) As 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 ScrollPane) As 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 ScrollPane) As String
    Dim SPJO As JavaObject = SP
    Return SPJO.RunMethod("getHbarPolicy",Null)
End Sub

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

Public Sub getInnerNodeActualWidth(SP As ScrollPane) As Double
    Dim INJO As JavaObject = SP.InnerNode
    Return INJO.RunMethod("getWidth",Null)
End Sub
 
Top