JavaFX Scene Builder - line break in button's text

Socrates picture Socrates · Feb 15, 2015 · Viewed 8.3k times · Source

How can I add a line break to a button's text when using the Scene Builder? Doing it in the controller's code (of the Java file) gives me what I want:
button.setText("one\ntwo");
results in
one
two
being displayed. But inserting one\ntwo into the button's text when using Scene Builder (and without the Java code mentioned above) results in one\ntwo being displayed.

There is a "Wrap Text" checkbox with which I was unsuccessful. I guess this is for making the text wrap when the button is not wide enough, but this is not the desired behavior.

Answer

José Pereda picture José Pereda · Feb 15, 2015

On Scene Builder, you can switch to multi-line mode, and start adding text and new lines.

Button text

With your text:

Button text 2

Then, if you edit the FXML file you will see that the usual line return \n is replaced with the html encoding for line feed: 
. So in your case:

<Button fx:id="button" text="one&#10;two" />