Mitchell Jeppson
Mitchell Jeppson

Reputation: 306

Lining up text in javafx label

I have a JavaFX application where I am updating 10 labels in a vbox. Below is the code that updates the labels:

String output = String.format("%-30s: %d", name, score);
labelArr[i].setText(output);

I would like the names to be aligned and the scores to be aligned, but here is what I am getting

not aligned textfields

*Excuse the dummy values

Upvotes: 0

Views: 236

Answers (2)

jpell
jpell

Reputation: 173

You could put the labels inside of a GridPane with two colums.

GridPane gp = new GridPane();

Upvotes: 2

yelliver
yelliver

Reputation: 5926

The simplest solution is using Monospace font:

label.setFont(new Font("Monospace", 12));

Upvotes: -1

Related Questions