Forum Stats

  • 3,875,115 Users
  • 2,266,806 Discussions
  • 7,912,086 Comments

Discussions

javafx.scene.shape.Path() why is it always beginning in the upper left corner ?

Marcello
Marcello Member Posts: 116
edited May 19, 2016 2:23AM in JavaFX 2.0 and Later

I have spent now hours on this simple problem. No matter which value i assign to someStartX or someStartY, the displayed line always starts in the upper left corner. Why ?

I would like to have the starting point somewhere at a specific coordinate that corresponds to an underlying Node of the same size they should have the same coord.-system !?)

[code]

public void start(Stage stage) throws Exception {

    Scene scene = new Scene(new Group());

    stage.setTitle("Checkbox Sample");
    stage.setWidth(230);
    stage.setHeight(120);

    Path path = new Path();
   
    float someStartX = 50.0f;
    float someStartY = 80.0f;
  
    path.getElements().add(new MoveTo(someStartX,someStartY));
    path.getElements().add(new LineTo(100.0f, 100.0f));

    VBox vbox = new VBox();
    vbox.getChildren().addAll(path);
    vbox.setSpacing(5);

    HBox root = new HBox();
    root.getChildren().add(vbox);

    ((Group) scene.getRoot()).getChildren().add(root);

    stage.setScene(scene);
    stage.show();

    }

[/code]

Best Answer

  • jsmith
    jsmith Member Posts: 2,856
    edited May 18, 2016 2:14PM Answer ✓

    VBox and HBox are managed layout panes, they organize their content top to bottom and left to right respectively.

    If you want to control positioning of elements yourself, you should place the elements in an unmanaged layout container such as a Pane or a Group.

Answers

This discussion has been closed.