1

假设我的 HBox 有以下孩子:

<HBox fx:id="hBox" xmlns="http://javafx.com/javafx/8.0.102-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.controllers.ChatMessageController">
   <children>
      <TextFlow>
      </TextFlow>
      <Label text="|" />
      <TextFlow>
      </TextFlow>
   </children>
</HBox>

这个 HBox 可以调整为任何值。我如何确保第一个 TextFlow 始终适合其内容的大小而无需换行?

换句话说 - 我希望第一个 TextFlow 在访问 HBox 空间方面具有最终优先级。

4

1 回答 1

1

你可以做

<HBox fx:id="hBox" xmlns="http://javafx.com/javafx/8.0.102-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.controllers.ChatMessageController">
   <children>
      <TextFlow>
         <HBox.hgrow><Priority fx:value="ALWAYS"/></HBox.hgrow>
      </TextFlow>
      <Label text="|" />
      <TextFlow>
         <HBox.hgrow><Priority fx:value="ALWAYS"/></HBox.hgrow>
      </TextFlow>
   </children>
</HBox>

显然,您将需要添加导入

<?import javafx.scene.layout.Priority ?>
于 2016-09-21T20:29:31.543 回答