B4J Question TextArea set Tab indent amount

BPak

Active Member
Licensed User
Longtime User
Is there a way to set the amount of space the TAB Key uses in TextArea ?
 

Daestrum

Expert
Licensed User
Longtime User
You can add an eventfilter and capture the tab and replace it with spaces.
(uses Reflection and JavaObject libraries)
B4X:
Sub Process_Globals
	Private fx As JFX
	Private MainForm As Form
	Dim ta As TextArea
	Dim ref As Reflector
	Dim keycode As JavaObject
	Dim tajo As JavaObject
End Sub

Sub AppStart (Form1 As Form, Args() As String)
	MainForm = Form1
	MainForm.Show
	keycode.InitializeStatic("javafx.scene.input.KeyCode")
	ta.Initialize("ta")
	tajo = ta
	MainForm.RootPane.AddNode(ta,10,10,-1,-1)
	ref.Target = ta
	ref.AddEventFilter("ta","javafx.scene.input.KeyEvent.KEY_PRESSED")
End Sub
Sub ta_Filter(e As Event)
	Dim KE As JavaObject = e
	' check for shift control etc as they are used for form navigation
	If KE.RunMethod("getCode",Null) = keycode.GetField("TAB") Then
		If KE.RunMethod("isAltDown",Null) Or KE.RunMethod("isControlDown",Null)  _
			Or KE.RunMethod("isShiftDown",Null) Or KE.RunMethod("isMetaDown",Null)Then
			Return
		End If
		e.Consume
		' the spaces in last parameter is what tab gets replaced with
		tajo.RunMethod("insertText",Array(tajo.RunMethodJO("getCaretPosition",Null),"  "))
	End If
End Sub
 
Upvote 0
Top