JTextArea 缩进设置

JTextArea Indentation settings

我想了解如何在按下键盘上的 'tab' 键时仅在 JTextArea 中向前移动 4 个空格。目前它向前移动了 8 个空格。

我阅读了 Java 中有关样式的一些内容,并遇到了 setLeftIndent() 但这不是我需要的。我考虑过使用键监听器,所以只要在 JTextArea 中按下 'tab',它只会向前移动 4 个空格(键绑定)。

如有任何建议,我将不胜感激。

谢谢。

可以使用JTextArea的setTabSize(...)方法:

textArea.setTabSize( 4);