B4J Code Snippet ComboBox Text_Changed event

There is a way to intercept the text that the user type inside an editable combo box before he presses return key (like for the textbox)?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private cmb As ComboBox
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   cmb.Initialize("cmb")
   cmb.Items.AddAll(Array("1", "2", "3"))
   cmb.Editable = True
   MainForm.RootPane.AddNode(cmb, 0, 0, 200, 50)
   MainForm.Show
   Dim jo As JavaObject = Me
   jo.RunMethod("AddTextChanged", Array(cmb, "cmb"))
End Sub

Sub cmb_TextChanged(Text As String)
   Log(Text)
End Sub

#If Java
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.ComboBox;
import anywheresoftware.b4a.BA;
public static void AddTextChanged(final ComboBox box, final String EventName) {
   box.getEditor().textProperty().addListener(new ChangeListener<String>() {

  @Override
  public void changed(ObservableValue<? extends String> observable,
  String oldValue, String newValue) {
  ba.raiseEventFromUI(box, EventName.toLowerCase() + "_textchanged", newValue);
  }
});
}
#End If
 
Top