Jonas Olsen
Jonas Olsen

Reputation: 33

Unable to Pos.CENTER in BorderPane

    BorderPane root = new BorderPane();

    Button chooseFile = new Button("chooseFile");
    TextField fileLocation = new TextField("C:/");
    Button makeGrid = new Button("Solve");
    HBox fileLoad = new HBox(chooseFile, fileLocation, makeGrid);

    root.setTop(lastfil);
    BorderPane.setAlignment(root, Pos.TOP_CENTER);
    BorderPane.setMargin(root, new Insets(12,12,12,12));
    root.setPrefSize(500, 500);

I'm having some issues centering this, I want the prefSize to be 500 x 500 and have the file loader top center, but it does not do that. It is top but I am unable to get it to the center of the top. Anything obvious I'm doing wrong?

Upvotes: 0

Views: 1002

Answers (1)

Keyur Bhanderi
Keyur Bhanderi

Reputation: 1544

BorderPane sets the alignment and Margin for the child node.

BorderPane.setAlignment(Node child, Pos value)

BorderPane.setMargin(Node child, Insets value)

So replace Borderpane 'root' to child node 'fileLoad ' as:

BorderPane.setAlignment(fileLoad, Pos.TOP_CENTER);
BorderPane.setMargin(fileLoad, new Insets(12,12,12,12));

Also set the child HBox alignment like:

fileLoad.setAlignment(Pos.CENTER);

Refer Class BorderPane to more info.

Upvotes: 1

Related Questions