B4J Question Password field and combo box text change event

Nokia

Active Member
Licensed User
Longtime User
How do I access the Password field and combo box in editable mode text change events?

I belive this is the event:

B4X:
passwordField.textProperty().addListener((obs, oldText, newText) -> {
    System.out.println("Password changed to: " + newText);
});
 
Solution
adding PasswordField as a javaobject to scene then adding handler after its added (tested on Java 26 and B4J 10.30 as working)
B4X:
Sub Class_Globals
    ...
    Dim pw As JavaObject
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    pw.InitializeNewInstance("javafx.scene.control.PasswordField",Null)
    Root.AddView(pw,50,200,400,20)
    Me.as(JavaObject).RunMethod("addHandler",Array(pw))
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click...

Nokia

Active Member
Licensed User
Longtime User
Not sure that I understand. If this is a TextField then you can handle its TextChanged event. You can also use B4XFloatTextField which is cross platform.
it's not a text field; it's a password field and a combo box with editable = true.

trying to get the text change event for those two controls.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
adding PasswordField as a javaobject to scene then adding handler after its added (tested on Java 26 and B4J 10.30 as working)
B4X:
Sub Class_Globals
    ...
    Dim pw As JavaObject
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    pw.InitializeNewInstance("javafx.scene.control.PasswordField",Null)
    Root.AddView(pw,50,200,400,20)
    Me.as(JavaObject).RunMethod("addHandler",Array(pw))
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

#if java
import javafx.scene.control.PasswordField;

public static void addHandler(PasswordField pw){
    pw.textProperty().addListener((obs, oldText, newText) -> {
            System.out.println("Password changed to: " + newText);
    });
}
#End If
 
Upvote 0
Solution

Nokia

Active Member
Licensed User
Longtime User

thanks for the point in the right direction.. U updated code to this and it works as I need it.

B4X:
    Dim pwd As JavaObject
    pwd.InitializeNewInstance("javafx.scene.control.PasswordField",Null)
    Dim joMe As JavaObject = Me
    Dim ba As Object = joMe.GetField("ba")
    Me.as(JavaObject).RunMethod("addHandler",Array(pwd, ba, Me))
    
#If java
import anywheresoftware.b4j.objects.PaneWrapper.ConcretePaneWrapper;
import anywheresoftware.b4a.BA;
import javafx.scene.control.PasswordField;

public static void addHandler(PasswordField pw, BA ba, Object b4xPage){
    pw.textProperty().addListener((obs, oldText, newText) -> {
        ba.raiseEventFromUI(b4xPage, "onpasswordchanged", newText);
    });
}
#End If

'calling this B4J sub
Sub OnPasswordChanged(NewPassword As String)
    'called from java code below   
    Dim strength As Int = pg.CalcPwdStrength(NewPassword)
    hp.Value = strength
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…