gpt4 book ai didi

javafx gridpane 布局与换行文本

转载 作者:行者123 更新时间:2023-11-30 07:41:52 27 4
gpt4 key购买 nike

我正在使用 JavaFX 8。尝试使用 GridPage 来显示一组属性和值。有些值可能太长,无法放在一行中。我想包装这些值,但似乎无法弄清楚如何使网格 Pane 垂直扩展以容纳包装的文本。我基本上想要像您在 HTML 表中看到的行为。不确定我应该使用 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

感谢任何帮助

最佳答案

使用 SceneBuilder 构建:

small large

<?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>

关于javafx gridpane 布局与换行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34550889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com