1

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?

  • 1
    Maybe use a `Pane` or another alignment for `StackPane`, for [example](http://stackoverflow.com/a/31443755/230513). – trashgod Jul 22 '15 at 03:46
  • @trashgod: Any reason why people post an answer as comment? It happens more and more and it's starting to get annoying because everyone's time is wasted. – Roland Jul 22 '15 at 06:08
  • possible duplicate of [Position JavaFX Button in a specific location](http://stackoverflow.com/questions/30641187/position-javafx-button-in-a-specific-location) – ItachiUchiha Jul 22 '15 at 09:17
  • @Roland: I'm new to [tag:javafx]. – trashgod Jul 23 '15 at 00:05

1 Answers1

1

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.

Hareesh
  • 694
  • 6
  • 18