How can I make the text use exactly the space that is avaliable to it?

65 Views Asked by At

The code that I currently have is:

<HBox fx:id="mainTagBody" id="mainTagBodyInOverview" alignment="CENTER" xmlns="http://javafx.com/javafx"
      stylesheets="@/client/stylesheets/Global.css"
      xmlns:fx="http://javafx.com/fxml"
      fx:controller="client.scenes.TagInOverviewCtrl">

    <HBox fx:id="tagContain" HBox.hgrow="ALWAYS">
        <Text fx:id="tagText" text="test" wrappingWidth="${tagContain.prefWidth}" />
    </HBox>

    <Button text="edit"/>

    <Button text="delete"/>

</HBox>

and this is how it looks:

No matter what I tried to do, the text would just either go through the edge, like this:

text goes into the abyss

and goes to the abyss, or like here:

stretch

extends the whole thing, moving the edge who knows where. I tried using the wrappingWidth in different ways, but none worked.

The way I intended for it to work is for the text to wrap when the tagContain hbox uses all available space, and avoid using exact numbers at all cost.

1

There are 1 best solutions below

0
hellwraiz On

I modified the code to look like this:

<HBox fx:id="mainTagBody" id="mainTagBodyInOverview" alignment="CENTER" xmlns="http://javafx.com/javafx"
      stylesheets="@/client/stylesheets/Global.css"
      xmlns:fx="http://javafx.com/fxml"
      fx:controller="client.scenes.TagInOverviewCtrl" prefWidth="300">
    <HBox fx:id="tagContain" HBox.hgrow="ALWAYS">
        <Label fx:id="tagText" text="test" wrapText="true" />
    </HBox>
    <Button fx:id="editTagButton" text="edit" minWidth="60" />
    <Button fx:id="deleteTagButton" text="delete" minWidth="70" />
</HBox>

That solved my issue