JavaFX Button with multiple text lines

前端 未结 6 2122
一个人的身影
一个人的身影 2021-01-13 04:35

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:

6条回答
  •  清歌不尽
    2021-01-13 05:22

    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.

提交回复
热议问题