B4J Code Snippet ComboBox Text_Changed event

Discussion in 'B4J Code Snippets' started by ziomorgan, Apr 19, 2015.

  1. ziomorgan

    ziomorgan Member Licensed User

    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Here:
    Code:
    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, 
    0020050)
       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
     
    ziomorgan likes this.
  3. ziomorgan

    ziomorgan Member Licensed User

    thanks, work perfectly
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice