0

I'm having a little trouble finding something similar to VBox (to set elements on top of each other), but that wouldn't autofit. I'm trying to create Gantti diagram, but if i create rectangles with small width and add text into VBox aswell and the number width is larger than my rectangle width it will choose number width. It becomes a problem when i start to put things next to each other with HBox().

I can show you the picture of it:

As seen from image, there is a whitespace between blue and black rectangles, these are caused by the width of numbers being higher than width of rectangles. I would like to ignore the number width and get rectangles exactly next to each other (Although keep the number in the center of middle rectangle). HBox has been created with value of 0 so there's no gap.

My code is written fully in estonian and i will provide an example code which is not from actual program but features the idea that i've done:

        HBox hbox1 = new HBox();
        VBox vbox1 = new VBox();
        Rectangle r1 = new Rectangle(0,0,30,30);
        Rectangle r2 = new Rectangle(0,0,5,50);
        r2.setFill(Color.BLUE);
        Rectangle r3 = new Rectangle(0,0,30,30);
        Text t1 = new Text();
        t1.setText(Integer.toString(222));
        vbox1.getChildren().addAll(r2,t1);
        hbox1.getChildren().addAll(r1,vbox1,r3);
        root.setBottom(hbox1);

Thanks in advance.

1 Answer 1

1

One of ways of doing this can be as follows:

Set the text node as unmanagable for its parent and determine its place manually

Text t1 = new Text();
t1.setText(Integer.toString(222));
t1.setManaged(false);
t1.setLayoutX(-t1.getLayoutBounds().getWidth() / 2);
t1.setLayoutY(r2.getHeight() + t1.getLayoutBounds().getHeight());
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.