Search code examples
javajavafxjavafx-css

How create Indent for letters in button. JavaFX


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.


Solution

  • 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);