1

Assuming that my HBox has a following children:

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

This HBox can be resized to any values. How can I make sure, that first TextFlow will always fit the size of its content without wrapping?

In other words - I wish the first TextFlow to have an ultimate priority in accesing HBox space.

Dejwi
  • 4,393
  • 12
  • 45
  • 74

1 Answers1

1

You can do

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

Obviously you will need to add the import

<?import javafx.scene.layout.Priority ?>
James_D
  • 201,275
  • 16
  • 291
  • 322
  • It should also be possible to specify this as simple attribute without the import ``. Type coercion should take care of selecting the correct enum constant automatically. – fabian Sep 21 '16 at 20:34
  • @fabian Thanks: I wasn't sure if that would work or not, and didn't have time to test... – James_D Sep 21 '16 at 20:37