简体   繁体   English

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

[英]How to make GridPane to accommodate label width in JavaFX?

I have added a few labels into GridPane and found, that long ones are shortened with ellipsis. 我在GridPane添加了一些标签,发现长标签用省略号缩短了。 While I would like long ones to push grid column width become wider as it occurs in MigLayout in Swing. 虽然我希望用较长的时间来推动网格列的宽度,因为它发生在Swing的MigLayout中。 Is it possible? 可能吗?

The function you are looking at is the "ALWAYS" value for parameter "hgrow" in columnconstraints. 您正在查看的功能是列约束中参数“ hgrow”的“ ALWAYS”值。 Check following code to understand how to use this functionnality in an fxml: 检查以下代码以了解如何在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>

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM