Wrapping Label text in a VBox using FXML

戏子无情 提交于 2019-12-05 10:39:09

Try to set prefWidth and prefHeight , since your label doesnt know when to start wrap

<VBox prefHeight="100.0" prefWidth="300.0"  ...

If that does not work try it on parent contrainer of HBox. Are you using scene builder? I recommend you to use it

Works well(its auto generated):

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="333.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
   <center>
      <VBox prefHeight="200.0" prefWidth="325.0" BorderPane.alignment="CENTER">
         <children>
            <Label text="Wrap text Wrap text Wrap text Wrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap textWrap text" wrapText="true" />
            <Label layoutX="10.0" layoutY="10.0" text="just textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust textjust text" />
         </children>
      </VBox>
   </center>
</BorderPane>

Did you use stylesheets there with class name "label1" and "label2" if you did, setting wrapText="true" will not work there in the fxml code

  1. You try to remove the id's and see if it wraps while wrapText="true" is still set

or

  1. Put some css code to that css file that would wrap text like this -fx-word-wrap: break-word; in the particular class;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!