B4J Question Mouse Scroll - Implementation Example

wonder

Expert
Licensed User
Longtime User
You can add an OnScroll event to a node with JavaObject:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   Dim jo As JavaObject = MainForm.RootPane
   Dim e As Object = jo.CreateEventFromUI("javafx.event.EventHandler", "scroll", Null)
   jo.RunMethod("setOnScroll", Array(e))
End Sub

Sub Scroll_Event (MethodName As String, Args() As Object) As Object
   Dim scrollevent As JavaObject = args(0)
   Log(scrollevent.RunMethod("getDeltaY", Null))
   Return Null
End Sub

Hi Erel,

I have a ListView named "Clipboard".
How can I use the mouse wheel to scroll through (and auto-select) the items?

I've tried:
B4X:
Sub ClipboardView_OnScroll
   ...
End Sub
Doesn't work. Can you post an implementation example?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm getting tired or repeating the same line: please don't limit your questions to a single member. This is a community forum.

You don't need to do anything special for it to scroll:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.Show
   Dim lv As ListView
   lv.Initialize("")
   For i = 1 To 100
     lv.Items.Add(i)
   Next
   MainForm.RootPane.AddNode(lv, 0, 0, 300, 300)
End Sub
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
You can do what you need using this code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    Dim joLv As JavaObject = lvClipboard
    Dim e As Object = joLv.CreateEvent("javafx.event.EventHandler", "Scroll", False)
    joLv.RunMethod("setOnScroll", Array(e))  
End Sub

Sub Scroll_Event (MethodName As String, Args() As Object) As Object
    Dim scrollevent As JavaObject = Args(0)
    If (scrollevent.RunMethod("getDeltaY", Null)) > 0 Then
        lvClipboard.SelectedIndex = lvClipboard.SelectedIndex - 1
    Else
        lvClipboard.SelectedIndex = lvClipboard.SelectedIndex + 1
    End If      
   Return Null
End Sub

Sub lvClipboard_SelectedIndexChanged(Index As Int)
    Log(Index)
End Sub

And I agree with Erel that anyone can help you!
 
Upvote 0
Top