0

I am trying to create a Container (in this case an HBox, but could be a StackPane, VBox, or otherwise); which contains a Group, and attached to the group is a MediaView.

If I simply create the objects without setting any margins etc., there appears a strange 9px gap between the start of the HBox (background blue below) and start of the Group (with MediaView attached coloured green below)

Image showing the problem - 9px gap between HBox and MediaView

If I explicitly use root.setTranslateX(-9); the HBox is moved over 9 pixels and the problem appears to be alleviated because it's been offset. This is, however, the only way I have found to solve this problem! Even if I use .setMargins(...); it still does this.

Problem "solved" by subtracting 9 pixels from HBox Position

Any ideas as to why this happens?

I attempted this again (code below). Interestingly it seems as though the gap is on the right.

Another attempt

    public class HelloWorld extends Application {

    HBox root = new HBox();
    MediaView view = new MediaView();

    public HelloWorld(){

    }
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");




        Group rootGroup = new Group();
        root.getChildren().add(rootGroup);
        root.setAlignment(Pos.CENTER_LEFT);
        root.setTranslateX(-9);
        root.setStyle("-fx-background-color: #039ED3;");
        rootGroup.getChildren().add(view);



        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}
ekad
  • 14,436
  • 26
  • 44
  • 46
Ben Hayward
  • 1,444
  • 23
  • 37
  • I don't see any gap on the right (or left) for Java 8u25 on OS X, the blue background for the HBox fills the entire scene for me. – jewelsea Feb 05 '15 at 23:31
  • Same here, no problems for Java 8u25 on Win7. – Roland Feb 06 '15 at 06:57
  • The gap on the right (in the blue example) is as a result of the -9 translation. I've tried with FX: 2.2.51-b13 & 8.0.40-ea-b17, and there aren't any gaps left or right if the -9 is commented out in either. – Jurgen Feb 06 '15 at 07:09
  • @Jurgen is very much correct - sorry about that. I still can't see what's wrong with my original code though (not published). Is it **OK** just to set a -9 translation to _cover up_ the problem? – Ben Hayward Feb 06 '15 at 11:31
  • Hacking it would be a last resort. First try using `setFitWidth` and `setPreserveRatio( false )` on the MediaView, and see what happens. – Jurgen Feb 06 '15 at 14:50

0 Answers0