Setting the tab spacing/size visualization for a J

2019-07-21 03:27发布

问题:

I am using JavaFX 8 and specifically the TextArea control. In that control I can enter free form text including "tab" characters. When I enter a tab, the data is spaced in units of 8 characters. For example. In the following, the ! character is where I enter a tab:

1234567890123456789012345678901234567890
!       Data here
ABC!    Data here
!!              Data Here

My puzzle is how to change the tab spacing/sizing for the visual so that instead of the tab size being 8 characters it will only be 4 characters.

To further illustrate, here is an actual screen shot showing tabs in my text area:

I want to leave the data as containing tab characters and not replace tabs with spaces.

This Stack Exchange question does not apply as it talks exclusively about changing tabs to space:

JavaFX TextArea: how to set tabulation width

回答1:

I decided to grunge through the source code of JavaFX to see if I could find an answer and, although I am not an expert in examining such a large amount of code, I seem to have found that the answer is that the tab size is hard-coded to be 8 characters!!

I found the source file called:

com.sun.javafx.text.PrismTextLayout.java

which has a method called getTabAdvance which returns a fixed value of "8". See the following:

This is most disappointing to me but it is what it is.