Jason Monsalve Jason Monsalve - 2 years ago 87
Java Question

how to center a label on a pane in javafx

I'd like to set results to the center of pane.

Label results = new Label("You win");
Pane pane = new Pane();

I've tried both lines of code below and neither works.


Btw, I know how to get this centered with StackPane and GridPane but in this case I need to use a plain Pane.

Answer Source

Pane does not support centering a child. Therefore it has to be done manually, i.e. the layoutX and layoutY positions have to be calculated "manually".

You can achieve this through binding:

// procede accordingly with layoutY / height
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download