Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Button with multiple text lines

I need to create a toolbar in my screen that will have multiple buttons, and each button must have multiple lines of Text. For example:

Button with multiple lines

I looked over the internet and StackOverflow but I couldn't find anything showing how to do this in JavaFX. I'm using JavaFX 8.

Someone could help me, please?

Tks

like image 416
henriqueor Avatar asked Dec 04 '14 13:12

henriqueor


4 Answers

Also you can use the wrapTextProperty. But you have to set toolbar height greater than expected button height.

Button btn = new Button();
btn.wrapTextProperty().setValue(true);
// or btn.setWrapText(true);
btn.setText("Some looooooooooooong text");

Or if you want to determine exactly where the line should be wrapped, you can go this way:

Button btn = new Button();
btn.setText("Line1\n Line2\n Line3");

Last way will work without changing toolbar height.

like image 110
soboliev.stp Avatar answered Nov 12 '22 06:11

soboliev.stp


I resolved this problem including a VBox inside my button, and then including several Labels inside the VBox. Like this:

enter image description here

The result is:

enter image description here

If there is a more elegant way to have the same result, please, let me know. Thank you.

like image 20
henriqueor Avatar answered Nov 12 '22 05:11

henriqueor


In the button text property select "switch to multi-line mode

enter image description here"

like image 3
Vishrant Avatar answered Nov 12 '22 05:11

Vishrant


From sobolev's response, you can do:

Button btn = new Button();
btn.setText("Line1\n Line2\n Line3");
button.textAlignmentProperty().set(TextAlignment.CENTER);

This will create 3 lines of text and allign them in the center of your button.

like image 1
Aibek Avatar answered Nov 12 '22 07:11

Aibek