B4J Question B4xDialog: Question about TAB key

Status
Not open for further replies.

Omar Moreno

Member
Licensed User
How can I make the cotrol B4XDialog avoid losing focus with the TAB key?

When the dialog is executed, the background of the screen becomes dark and
with the mouse you cannot activate the objects of the root form, but pressing the TAB key
you can jump out of the dialog control.

Thanks for the help.
 

Omar Moreno

Member
Licensed User
The code of post # 2 is functional for dialogs that do not use input text, but in my case I do use them, so use that of post # 1 using e.consume.
If you press the TAB key, blocking the jump out of the dialog, but the TAB cycle only works once or I don't know where the focus goes.

B4X:
Private Sub AddKeyPressedListener
    Try
        '
        Dim r As Reflector
        r.Target = Main.MainForm.RootPane
        r.AddEventHandler("keypressed", "javafx.scene.input.KeyEvent.KEY_PRESSED")
        '
    Catch
        Log($"AddKeyPressedListener: ${LastException.Message}"$)
    End Try
End Sub

Private Sub KeyPressed_Event(e As Event)
    Try
        '
        If VModal.Visible Then
            Dim jo As JavaObject = e
            Dim keycode As String = jo.RunMethod("getCode", Null)
            Select keycode
                Case "ESCAPE"
                    VModal.Close(XUI.DialogResponse_Cancel)
                Case "TAB"                       
                    e.Consume  '<-------
                    'Some function to know where the focus is ...
            End Select
        End If
        '
    Catch
        Log($"KeyPressed_Event: ${LastException.Message}"$)
    End Try
End Su
 

Daestrum

Well-Known Member
Licensed User
Could you requestFocus on the dialogue (VModal) when TAB key is pressed after the e.Consume line.
 

TomKluz

Active Member
Licensed User
I am watching this thread with a great interest. I have the same problem with a B4J Dialog with input text. Tab key is going "somwhere" and in fact I am looseing control
with focus. For me it is also fine if Tab key could be just locked. Unfortunatelly I don't know how to do it.
 

Erel

Administrator
Staff member
Licensed User
Disabling tag should be simple. Something like:
B4X:
r.AddEventFilter("keypressed", "javafx.scene.input.KeyEvent.ANY")

Sub KeyPressed_Filter (e As Event)
   If Dialog.Visible Then
       Dim jo As JavaObject = e
       Dim EventType As String = jo.RunMethodJO("getEventType", Null).RunMethod("getName", Null)
       If EventType = "TAB" Then
          e.Consume
       End If
   End If
End Sub
You can also modify it to switch to the next text field. It will require monitoring the currently focused field.
 

TomKluz

Active Member
Licensed User
Hello,
Unfortunatelly can't start it. Probably I don't know how to declare r or maybe some library is missing.
Here I have attached test app. May I ask to check what is wrong ?
May I ask to point me also for tutorial or ather example to understand it ?

Thank you in advance
 

Attachments

TomKluz

Active Member
Licensed User
I have found jReflection library (written by Andrew Graham) description on B4X web learning section, but I can't find it on a list of B4J internal libraries.
Finally found within a thread jReflection library as zip.
Is it a right source ?

P.S.
Now I have discovered an option in B4J IDE 'Export as zip'. Thank you.
 

TomKluz

Active Member
Licensed User
I have found jReflection but don't know how to initialize Dialog. Unfortuatelly I don't understand a lot.
Cannot start text_fields test app.
May I ask you to help me, please.

Tomkluz
 

Attachments

TomKluz

Active Member
Licensed User
As I understand locking a Tab key is possible only using XUI views and dialog libraries. So text field is declared as B4XFloatTextField but not as TextField.

Sorry for asking so simple questions.
Is it the only way ? No other more simle solution ?

Kind regards
 

Erel

Administrator
Staff member
Licensed User
As I understand locking a Tab key is possible only using XUI views and dialog libraries. So text field is declared as B4XFloatTextField but not as TextField.
That is 100% incorrect and it happens because you are posting your questions in a thread that discusses different things. You should always start a new thread for your question.
 
Status
Not open for further replies.
Top