Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Scene Builder - line break in button's text

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.

like image 337
Socrates Avatar asked Feb 15 '15 19:02

Socrates


1 Answers

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" />
like image 56
José Pereda Avatar answered Oct 31 '22 17:10

José Pereda