7

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.

Socrates
  • 103
  • 1
  • 3
  • 8

1 Answers1

21

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" />
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • 1
    That Scene Builder ... the extra button next to that text field only appears when the mouse hovers over it. But why should an unknowing user place the mouse there? :-) – Socrates Feb 15 '15 at 19:21
  • 1
    Yes, there're quite a few 'hidden' options. Usually all the controls in the Inspector tab have a not visible button on the right with extra options, mainly to reset to default values, visible only on hovering. – José Pereda Feb 15 '15 at 19:23