3 Replies Latest reply on Oct 17, 2012 3:15 PM by shakir.gusaroff

    Box allignment (new to javafx)


      im new to java fx and have a small problem with allignment.

      I have a VBox (inner) in an HBox (outer) and what i want to do is, when i resize my scene, i want that the VBox is always allignt in the right side of the HBox.
      I pretty much tried everything right now with Allignments stuff but couldnt figure it out.

      Is there any way to do this with Boxes or shall i use grids or borderpane?
        • 1. Re: Box allignment (new to javafx)

          I suspect that your issue is that the HBox resizes the inner VBox - so the VBox always takes all the available horizontal space.
          Try setting the VBox max size to Region.USE_PREF_SIZE in addition to setting the HBox alignment. This should
          prevent the VBox to grow horizontally.

          if you want to see where the boundaries of your VBox and HBox are, you can set a background color in their style property:

          vbox.setStyle("-fx-background-color: pink;");
          hbox.setStyle("-fx-background-color: red;");

          hope this helps,

          -- daniel
          • 2. Re: Box allignment (new to javafx)
            David Grieve-Oracle
            Using setStyle, as Daniel recommends, is an excellent tool for debugging. FWIW, I use -fx-border-color instead of -fx-background-color since very few controls, if any, use border color and the color doesn't interfere with the contents.
            • 3. Re: Box allignment (new to javafx)
              Hi. Try the following:
                      HBox hb = new HBox();
                      VBox vb = new VBox();
                      vb.getChildren().addAll(new Button("Submit"), new Label("label"));
                      HBox.setHgrow(vb, Priority.ALWAYS);
                      Scene scene = new Scene(hb, 300, 250);