Reputation: 33
I have a problem with changing the location of my Button i want to set a Specific location where to put it but when i use .setLayoutX
and .setLayoutY
i even tried using .relocate
and it is still not working am i doing something wrong? here is my sample code.
CODE
Button b1 = new Button();
b1.setText("Press");
b1.setLayoutX(100);
b1.setLayoutY(120); // this are just some randome numbers for this sample
StackPane pane = new StackPane();
pane.getChildren().add(b1);
Scene scene = new Scene(pane,500,500);
stage.setScenes(scene);
stage.show();
when i run the program the button is still in the center of the screen am doing something wrong?
Upvotes: 1
Views: 1740
Reputation: 734
Use Anchor pane or a pane to align nodes as per your layout. StackPane, GridPane and many panes they come with inbuilt layout methods, you dont have control on locating the nodes based on x and y values.
Upvotes: 1