0

I'm writing a text editor in JavaFX with the RichTextFX library and when I write a tab it has a width of 8. How can I change this without replacing the tab with e.g. 4 whitespaces?

This is what I have at the moment:

Nodes.addInputMap(this.codeArea, InputMap.consume(EventPattern.keyPressed(KeyCode.TAB), e -> {
    this.codeArea.replaceSelection("    ");
}));

It replaces a tab with 4 whitespaces but how can I make that one tab is displayed with a width of 4 whitespaces?

Thank you for answering!

1 Answers1

2

This depends on what version of JavaFX you are using. This https://bugs.openjdk.java.net/browse/JDK-8130738 was implemented in JavaFX 14.

See: https://openjfx.io/javadoc/14/javafx.graphics/javafx/scene/text/TextFlow.html#tabSizeProperty

and: https://openjfx.io/javadoc/14/javafx.graphics/javafx/scene/doc-files/cssref.html#text

swpalmer
  • 3,890
  • 2
  • 23
  • 31
  • How do i get the textflow of the code area? i tried this but its not working: -fx-tab-size: 8px; So i ended up increasing the font size and scaling the actual component for a smaller tab. – Jp Silver Nov 22 '20 at 05:13
  • 1
    @JpSilver check the docs for the CSS property, it takes an integer only. The number of "spaces" in a Tab. – swpalmer Nov 22 '20 at 14:51
  • Thank you good sir. Its working now. I thought it had to be px because of intellij's intellisence haha, seems obvious now, witch it actually is. Thank you! – Jp Silver Nov 23 '20 at 10:06