如何使GridPane适应JavaFX中的标签宽度?

时间:2016-04-26 13:32:55

标签: java javafx javafx-8 scenebuilder

我在GridPane中添加了一些标签,发现长标签用省略号缩短了。虽然我希望很长的推动网格列宽度变得更宽,因为它发生在Swing中的MigLayout中。有可能吗?

1 个答案:

答案 0 :(得分:0)

您正在寻找的功能是"总是"参数" hgrow"的值在columnconstraints中。检查以下代码以了解如何在fxml中使用此功能:

<GridPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
          minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40">
    <columnConstraints>
        <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0"/>
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
    </columnConstraints>
    <rowConstraints>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
    </rowConstraints>
    <children>
        <Label text="abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" GridPane.rowIndex="1"/>
    </children> </GridPane>

希望它有所帮助。