0

I have standard button and me need create indent for letters in this button, how it do? Sorry behind my English..

I had tried find in documentation JavaFX CSS the decision but him not or i him no find. Example how should to look like text in button: T e x t.

Dokat
  • 11
  • 1
  • Are you just looking to add [padding](https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/layout/Region.html#setPadding(javafx.geometry.Insets))? – James_D Jan 05 '23 at 15:55
  • I want add indents between letters – Dokat Jan 05 '23 at 15:59
  • 2
    In HTML CSS this is known as [`letter-spacing`](https://developer.mozilla.org/en-US/docs/Web/CSS/letter-spacing). However, JavaFX will only support HTML CSS for HTML displayed inside a WebView, not on standard JavaFX controls like Labels or TextFields. It may not even support letter spacing within a WebView (I haven't tried it). Letter spacing is related to [Kerning](https://en.wikipedia.org/wiki/Kerning), though a little different. Custom Kerning is also not supported by the JavaFX font engine. – jewelsea Jan 05 '23 at 22:22
  • Perhaps try to use [a custom font](https://stackoverflow.com/questions/16855677/how-to-embed-ttf-fonts-in-javafx-2-2). Either you could try to search for a font that defaults to a wide letter spacing, or you may be able to [modify an existing font to adjust its spacing](https://graphicdesign.stackexchange.com/a/10633). I've never done either and further advice on how to do that would be out of scope for what I could answer here. – jewelsea Jan 05 '23 at 22:28

1 Answers1

1

You can do something like the following:

final int spacing = 8; // pixels between each letter
final String buttonText = "Text"; // text to display
Button button = new Button();
HBox graphic = new HBox(spacing);
for (int i=0; i<buttonText.length(); i++) {
    graphic.getChildren().add(new Label(buttonText.substring(i, i+1)));
}
button.setGraphic(graphic);
James_D
  • 201,275
  • 16
  • 291
  • 322