B4J Question ComboBox using an AnchorPane as the list item

alwaysbusy

Expert
Licensed User
Longtime User
I'm having some trouble using AnchorPanes as items the ComboBox. When first opened, they look fine. However, once I select one, the selected one comes 'invisible' in the list. Must be something I'm missing.

Note the below code is a simplified version. In my real code I use an anchorpane as item with images, multiple labels etc.

Here is a demo demonstrating the behaviour:

B4X:
#Region  Project Attributes
   #MainFormWidth: 600
   #MainFormHeight: 400
#End Region

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 Params As List
   Params.Initialize
   Params.Add("Value 3")
   Params.Add("Value 1")
   Params.Add("Value 2")
   Params.Add("Value 3")
   Params.Add("Value 4")
   Params.Add("Value 5")
   
   Dim p As AnchorPane  
   p.Initialize("mypanel")
   Dim cmb As ComboBox
   cmb.Initialize("")
   Dim selIndex As Int
   For i = 1 To Params.Size - 1
  If Params.Get(0) = Params.Get(i) Then
  selIndex = i-1
  End If
  Dim lbl As Label
  lbl.Initialize("")
  lbl.Text = Params.Get(i)
  cmb.Items.Add(lbl)
   Next
   cmb.SelectedIndex = selIndex
   p.AddNode(cmb,0,-2,300, 28)
   
   MainForm.RootPane.AddNode(p,0,0,300,600)
End Sub
 
Top