Android Question B4XComboBox Scroll to item

MarcoRome

Expert
Licensed User
Longtime User
Hi All.
Is it possible via code to scroll B4XComboBox (type jumpto of clv) ?
Any suggestion
Thank you
 

MarcoRome

Expert
Licensed User
Longtime User
Do you mean B4XComboBox's SelectedIndex?
No, with SelectedIndex it arrives at the desired index but does not scroll.
To give an example: If I have 100 items from 1 to 100 and I select SelectIndex = 50 it selects the item but when i open the combo i still have to scroll up to the 50th item
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Is it like this?

2024-05-28-01-09-54.gif
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Yes. Exactly this.
Can you share the code pls :)
In B4A it just is SelectedIndex
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Dim Items As List
    Items.Initialize
    For i = 1 To 100
        Items.Add($"Item #${i}"$)
    Next

    B4XComboBox1.SetItems(Items)
    B4XComboBox1.SelectedIndex=49
    
End Sub
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Unfortunately it doesn't have the same result on B4J.


Yes right i should have opened the thread on B4J, but I thought it was the same for the 3 environments B4J, B4A, B4i
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Unfortunately it doesn't have the same result on B4J.
Yes right i should have opened the thread on B4J, but I thought it was the same for the 3 environments B4J, B4A, B4i
Here is B4J solution, project is attached.
2024-05-28-20-44-33.gif
 

Attachments

  • b4xcmbscrollTo.zip
    2.5 KB · Views: 82
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Here is B4J solution, project is attached.
View attachment 154111

Hi @teddybear thank you for your time.
This solution works perfectly on Java 14.
Unfortunately on Java 19 it has the following crash.

WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
java.lang.StackOverflowError
at javafx.controls/javafx.scene.control.skin.VirtualFlow.getVisibleCell(VirtualFlow.java:1418)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.getOrCreateCellSize(VirtualFlow.java:3024)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.getOrCreateCellSize(VirtualFlow.java:2998)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCellSizesInExpectedViewport(VirtualFlow.java:2321)
at javafx.controls/javafx.scene.control.skin.VirtualFlow.scrollToTop(VirtualFlow.java:1573)
at javafx.controls/javafx.scene.control.skin.VirtualContainerBase.lambda$new$0(VirtualContainerBase.java:82)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.controls/javafx.scene.control.ControlUtils.lambda$scrollToIndex$0(ControlUtils.java:47)
at javafx.controls/com.sun.javafx.scene.control.skin.Utils.executeOnceWhenPropertyIsNonNull(Utils.java:835)
at javafx.controls/javafx.scene.control.ControlUtils.scrollToIndex(ControlUtils.java:46)
at javafx.controls/javafx.scene.control.ListView.scrollTo(ListView.java:933)
at b4j.example.main$1.call(main.java:144)
at b4j.example.main$1.call(main.java:141)
...

I have to use Java 19 because I use the map and the library only works on Java 19 and not 14
'V2.00 - Depends on OpenJDK 19. Previous versions will not work.

I also tried adding #VirtualMachineArgs: -Djavafx.allowjs=true as suggested

and unfortunately it doesn't change the error remains
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
In a project I had to resort to this technique.

It's a call with a 250 millisecond wait for it to work:


in my clv form container:

B4X:
Sub Activity_Resume ': modGeneral.clsConnec.SetObject(Me)
'---blablabla
'if blablabl
    JumpToUltimo
end if
'---blablabla

End Sub


B4X:
private Sub JumpToUltimo
    Try
        
        Starter.csu.CallSubPlus2(Me, "clv1_Jump",  250,Array("25"))
    Catch
        Log(LastException)
    End Try

End Sub

in a class (clsCallSubUtils):

B4X:
'Class module
Sub Class_Globals
    Private RunDelayed As Map
    Type RunDelayedData (Module As Object, SubName As String, Arg() As Object, Delayed As Boolean)
End Sub

Public Sub Initialize

End Sub

'Similar to CallSubDelayed. This method allows you to set the delay (in milliseconds).
'Note that the sub name must include an underscore if compiled with obfuscation enabled.
Public Sub CallSubDelayedPlus(Module As Object, SubName As String, Delay As Int)
    CallSubDelayedPlus2(Module, SubName, Delay, Null)
End Sub

'Similar to CallSubDelayed. This method allows you to set the delay (in milliseconds).
'Note that the sub name must include an underscore if compiled with obfuscation enabled.
'The target sub should have one parameter with a type of Object().
Public Sub CallSubDelayedPlus2(Module As Object, SubName As String, Delay As Int, Arg() As Object)
    PlusImpl(Module, SubName, Delay, Arg, True)
End Sub

'Similar to CallSub. This method allows you to set the delay (in milliseconds).
'Note that the sub name must include an underscore if compiled with obfuscation enabled.
Public Sub CallSubPlus(Module As Object, SubName As String, Delay As Int)
    Try
        
        CallSubPlus2(Module, SubName, Delay, Null)
    Catch
        Log(LastException)
    End Try

End Sub

'Similar to CallSub. This method allows you to set the delay (in milliseconds).
'Note that the sub name must include an underscore if compiled with obfuscation enabled.
'The target sub should have one parameter with a type of Object().
Public Sub CallSubPlus2(Module As Object, SubName As String, Delay As Int, Arg() As Object)
    PlusImpl(Module, SubName, Delay, Arg, False)
End Sub

Private Sub PlusImpl(Module As Object, SubName As String, Delay As Int, Arg() As Object, delayed As Boolean)
    If RunDelayed.IsInitialized = False Then RunDelayed.Initialize
    Dim tmr As Timer
    tmr.Initialize("tmr", Delay)
    Dim rdd As RunDelayedData
    rdd.Module = Module
    rdd.SubName = SubName
    rdd.Arg = Arg
    rdd.delayed = delayed
    RunDelayed.Put(tmr, rdd)
    tmr.Enabled = True
End Sub

Private Sub tmr_Tick
    Dim t As Timer = Sender
    t.Enabled = False
    Dim rdd As RunDelayedData = RunDelayed.Get(t)
    RunDelayed.Remove(t)
    If rdd.Delayed Then
        If rdd.Arg = Null Then
            CallSubDelayed(rdd.Module, rdd.SubName)
        Else
            CallSubDelayed2(rdd.Module, rdd.SubName, rdd.Arg)
        End If
    Else
        If rdd.Arg = Null Then
            CallSub(rdd.Module, rdd.SubName)
        Else
            CallSub2(rdd.Module, rdd.SubName, rdd.Arg)
        End If
    End If
End Sub

and in starter:

B4X:
    Public csu As clsCallSubUtils
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Is there also a B4i solution for this, that works with the action sheet, which is used for B4XComboBox in iOS?
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
You should always create a new thread for any Issue you have. In this case also in the correct subforum.
The biggest part in this thread was about B4J in B4A subforum. So I thought one more solution for B4i also would make the matter complete. My mistake...
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
The biggest part in this thread was about B4J in B4A subforum. So I thought one more solution for B4i also would make the matter complete. My mistake...
Also mine.
But as i said in thread #7: "Yes right i should have opened the thread on B4J, but I thought it was the same for the 3 environments B4J, B4A, B4i"
 
Upvote 0
Top