假设我的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空间时具有最终的优先级。
你可以做
<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 ?>