简体   繁体   English

带换行文字的javafx gridpane布局

[英]javafx gridpane layout with wrapping text

I am working in JavaFX 8. Trying to use the GridPage to display a set of attributes and values. 我正在JavaFX 8中工作。尝试使用GridPage显示一组属性和值。 Some of the values may be long enough to not fit on one line. 其中一些值可能足够长而无法容纳在一行上。 I would like to wrap those values, but can't seem to figure out how to get the grid pane to expand vertically to accommodate the wrapped text. 我想包装这些值,但似乎无法弄清楚如何使网格窗格垂直扩展以容纳包装的文本。 I Basically want behavior like you'd see in an HTML table. 我基本上想要的行为就像您在HTML表格中看到的那样。 Not sure if there is a different layout in JavaFX I should be using. 不知道我应该使用的JavaFX中是否有其他布局。

Property A    Value A
Property B    Value B
Property C    The Values for property C is so long
              that it wraps
Property D    Value D

Any help is appreciated 任何帮助表示赞赏

Constructed using SceneBuilder : 使用SceneBuilder构造

小 大

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<VBox prefWidth="220.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <GridPane hgap="20.0" vgap="10.0">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" />
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="20.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints minHeight="-Infinity" valignment="TOP" vgrow="SOMETIMES" />
          <RowConstraints minHeight="-Infinity" valignment="TOP" vgrow="SOMETIMES" />
          <RowConstraints minHeight="-Infinity" valignment="TOP" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <Label text="Property A" />
            <Label text="Property B" GridPane.rowIndex="1" />
            <Label text="Property C" GridPane.rowIndex="2" />
            <Label text="Value A" GridPane.columnIndex="1" />
            <Label text="The value for property B is so long that it wraps" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="1" />
            <Label text="Value C" GridPane.columnIndex="1" GridPane.rowIndex="2" />
         </children>
         <padding>
            <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
         </padding>
      </GridPane>
   </children>
</VBox>

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

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