B4J Question How to lock a Tab key ? SOLVED

TomKluz

Active Member
Licensed User
I am trying to print a raport. Some info I have to input manualy filling few texfields. Everything seems to be fine till I press Tab key. Then I can't controll focus (active textfield in my case). For me it is fine if a could just lock a Tab key and don't allow to go into all buttons on my panel.
I am attaching a test app to explain a problem.

Is it a way to lock a Tab key ?

Thank you for you help
 

Attachments

klaus

Expert
Licensed User
You can do it with this routine:
B4X:
Private Sub SetFocusTraversable(N As Node, Value As Boolean)
    Private jo As JavaObject
    jo = N
    jo.RunMethod("setFocusTraversable", Array As Object(Value))
End Sub
Example, the Tab key has no effect on Button1 and Button2:
B4X:
SetFocusTraversable(Button1, False)
SetFocusTraversable(Button2, False)
Attached your project modified.
 

Attachments

Erel

Administrator
Staff member
Licensed User
Another option:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
   MainForm.Show
   TextField1.RequestFocus
   AddKeyPressedListener
End Sub

Sub AddKeyPressedListener
   Dim r As Reflector
   r.Target = MainForm.RootPane
   r.AddEventFilter("keypressed", "javafx.scene.input.KeyEvent.ANY")
End Sub

Sub KeyPressed_Filter (e As Event)
   Dim jo As JavaObject = e
   Dim keycode As String = jo.RunMethod("getCode", Null)
   If keycode = "TAB" Then e.Consume
End Sub
 

TomKluz

Active Member
Licensed User
Hello,
Thank you very much to both of you. Problem is solved in two ways:
1. Tab key is working but some specific nodes (texfields or buttons) are protected against 'intruder' (Mr Klaus).
2. Tab key is locked indeed. Don't work at all (Mr Erel).

Both are effectiv. My gratefullnes is so huge as mountains around Mr Klaus.
Thanks again.
 
Top