1

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.

hellwraiz
  • 359
  • 2
  • 13
  • 5
    You should probably be using a [`Label`](https://openjfx.io/javadoc/19/javafx.controls/javafx/scene/control/Label.html), not [`Text`](https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/text/Text.html). `Text` is a fixed-sized shape, whereas a label is a dynamically sizable [`Region`](https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/layout/Region.html). – jewelsea Mar 30 '23 at 00:25
  • Where do you set or specify tagContain.prefWidth? – Thomas Mar 30 '23 at 08:37
  • Checkout binding concept to influence the wrappingWidth during runtime. – Thomas Mar 30 '23 at 08:44
  • Does this answer your question? [How to make JavaFX text wrap work?](https://stackoverflow.com/questions/40631744/how-to-make-javafx-text-wrap-work) – Thomas Mar 30 '23 at 09:01
  • @Thomas if you look at this line in the code: ``, the last part is where `tagContain.prefWidth` is set. And it is exactly what they do in that page that you suggested, but just fxml instead of JavaFX code. – hellwraiz Mar 30 '23 at 10:53
  • 1
    @jewelsea It worked using labels, thanks! Using the regionShape's default value and wrapText, after I added the prefWidth to the most outer hbox, the labels worked perfectly like I intended. – hellwraiz Mar 30 '23 at 11:47

1 Answers1

1

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

hellwraiz
  • 359
  • 2
  • 13