B4J Code Snippet [B4J] Text Input Dialog with JavaObject

For use JavaFx TextInput Dialog

B4X:
        Dim jo As JavaObject
        jo.InitializeNewInstance("javafx.scene.control.TextInputDialog", Null)
        jo.RunMethodJO("setTitle", Array As String("Sample Title"))
        jo.RunMethod("setHeaderText", Array As String("Sample Text"))
        

        If jo.RunMethodjo("showAndWait", Null).RunMethod("isPresent", Null)=True Then
            'ok button pressed
            Dim txt As String=jo.RunMethodJO("getEditor", Null).RunMethod("getText", Null)
            Log(txt)
        End If
 

peacemaker

Expert
Licensed User
Longtime User
Good example, thanks !
The default value:
B4X:
jo.InitializeNewInstance("javafx.scene.control.TextInputDialog", Array As String(DefaultValue_or_Variable))
 

aeric

Expert
Licensed User
Longtime User
Label on the left of the Text Input (Content Text):
B4X:
jo.RunMethod("setContentText", Array As String("Value:"))

10519106.png


 

Star-Dust

Expert
Licensed User
Longtime User
It is possible to insert more fields, but also ComboBox etc ..

How would you do it in B4J?

1654514359161.png


B4X:
Dim dialog As JavaObject
dialog.InitializeNewInstance("javafx.scene.control.TextInputDialog", Null)
dialog.RunMethodJO("setTitle", Array As String("Sample Title"))
dialog.RunMethod("setHeaderText", Array As String("Sample Text"))

Dim dialogPane As JavaObject = dialog.RunMethod("getDialogPane",Null)
Dim BasePane As Pane = dialogPane.RunMethod("getContent",Null)
Dim T2 As TextField
T2.Initialize("T2")
T2.Text="Hallo"
BasePane.AddNode(T2,0,0,-1,-1)

If dialog.RunMethodjo("showAndWait", Null).RunMethod("isPresent", Null)=True Then
        'ok button pressed
        Dim txt As String=dialog.RunMethodJO("getEditor", Null).RunMethod("getText", Null)
        Log(T2.Text & " " & txt)
End If
 

Star-Dust

Expert
Licensed User
Longtime User
Items in Hidden panel

1654518448774.png
1654518474371.png



B4X:
Dim dialog As JavaObject
dialog.InitializeNewInstance("javafx.scene.control.TextInputDialog", Null)
dialog.RunMethodJO("setTitle", Array As String("Sample Title"))
dialog.RunMethod("setHeaderText", Array As String("Sample Text"))

Dim dialogPane As JavaObject = dialog.RunMethod("getDialogPane",Null)
Dim BasePane As Pane = dialogPane.RunMethod("getContent",Null)

Dim L1 As Label
L1.Initialize("")
L1.Text = " First row"
BasePane.AddNode(L1,0,0,-1,-1)

Dim T2 As TextField
T2.Initialize("T2")
T2.Text="Hallo"
'BasePane.AddNode(T2,0,0,-1,-1)

Dim L2 As Label
L2.Initialize("")
L2.Text = " Second row"

Dim PaneNew As Pane
PaneNew.Initialize("")
PaneNew.AddNode(L2,12,0,90,-1)
PaneNew.AddNode(T2,120,0,-1,-1)
PaneNew.prefHeight=50

dialogPane.RunMethod("setExpanded",Array(True))
dialogPane.RunMethod("setExpandableContent",Array(PaneNew))

PS.: If you want to customize the main panel and not the extendable one, just assign the panel like this
B4X:
dialogPane.RunMethod("setContent",Array(PaneNew))
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Another solution

Obviously, the creation of the panel and the TextView can be done more easily from Design than from code.
ATTENTION: Using the XUI VIEW dialogs you will do before, this is just an example

B4X:
Private Sub PanelTwoField
            Dim dialog As JavaObject
            dialog.InitializeNewInstance("javafx.scene.control.TextInputDialog", Null)
            dialog.RunMethodJO("setTitle", Array As String("Ttile"))
            dialog.RunMethod("setHeaderText", Array As String("HEADER"))
    
            Dim dialogPane As JavaObject = dialog.RunMethod("getDialogPane",Null)

            Dim PaneNew As B4XView = xui.CreatePanel("")  ' Create New Panel
            Dim txt1 As B4XView =CreateTextField("txt1",row(1)) ' Add Text Filed 1
            Dim txt2 As B4XView =CreateTextField("txt2",row(2)) ' Add Text Filed 2
            PaneNew.AddView(CreateLabel("Field 1"),10,10,80,30) ' Add Laleb 1
            PaneNew.AddView(txtModello,100,10,220,30) 
            PaneNew.AddView(CreateLabel("Field 2"),10,50,80,30) ' Add Laleb 1
            PaneNew.AddView(txtDescrizione,100,50,220,30)
            PaneNew.Height=90
            dialogPane.RunMethod("setContent",Array(PaneNew)) ' Add Panel with 2 field
            
            If dialog.RunMethodjo("showAndWait", Null).RunMethod("isPresent", Null)=True Then
                log(txt1.Text)
                Log(txt2.Text)
            End If
End Sub

Private Sub CreateLabel(Text As String) As B4XView
    Dim L As Label 
    L.Initialize("")
    L.Text=Text
    Return L
End Sub

Private Sub CreateTextField(EventN As String, Text As String) As B4XView
    Dim T As TextField
    T.Initialize(EventN)
    T.Text=Text
    Return t
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
Dialog with password
B4X:
Dim dialog As JavaObject
    dialog.InitializeNewInstance("javafx.scene.control.TextInputDialog", Null)
    
    'Dim F As Form =  dialog.RunMethodJO("getDialogPane",Null).RunMethodJO("getScene",Null).RunMethodJO("getWindow",Null).
    dialog.RunMethodJO("getDialogPane",Null).RunMethodJO("getScene",Null).RunMethodJO("getWindow",Null).RunMethodJO("setAlwaysOnTop",Array(True))
    dialog.RunMethodJO("setTitle", Array As String("Security"))
    dialog.RunMethod("setHeaderText", Array As String("Insert Password"))
    
    Dim dialogPane As JavaObject = dialog.RunMethod("getDialogPane",Null)
    Dim BasePane As Pane = dialogPane.RunMethod("getContent",Null)
    Dim Pss As TextField
    BasePane.RemoveAllNodes
    Pss.InitializePassword("Pss")
    BasePane.AddNode(Pss,0,0,-1,-1)

    If dialog.RunMethodjo("showAndWait", Null).RunMethod("isPresent", Null)=True Then
        log(Pss.Text)
    End If
 

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Dialog with password
B4X:
Dim dialog As JavaObject
    dialog.InitializeNewInstance("javafx.scene.control.TextInputDialog", Null)
   
    'Dim F As Form =  dialog.RunMethodJO("getDialogPane",Null).RunMethodJO("getScene",Null).RunMethodJO("getWindow",Null).
    dialog.RunMethodJO("getDialogPane",Null).RunMethodJO("getScene",Null).RunMethodJO("getWindow",Null).RunMethodJO("setAlwaysOnTop",Array(True))
    dialog.RunMethodJO("setTitle", Array As String("Security"))
    dialog.RunMethod("setHeaderText", Array As String("Insert Password"))
   
    Dim dialogPane As JavaObject = dialog.RunMethod("getDialogPane",Null)
    Dim BasePane As Pane = dialogPane.RunMethod("getContent",Null)
    Dim Pss As TextField
    BasePane.RemoveAllNodes
    Pss.InitializePassword("Pss")
    BasePane.AddNode(Pss,0,0,-1,-1)

    If dialog.RunMethodjo("showAndWait", Null).RunMethod("isPresent", Null)=True Then
        log(Pss.Text)
    End If
How can I place the logo in the Dialog window
 
Top