How to center a label on a specific position?

javafx how to set center position for text or label?

  • How to set centerX and centerY for Text or Label node in JavaFX? AFAIK, there is no specific property (or method) for center position, but there are setLayoutX, setLayoutY methods + relocate, which I can't understand how they work.

  • Answer:

    You have to tell to your parent layout how to display children. Not children how to display themself. For example if your button is inside an Hbox just do : hbox.setAlignment(Pos.CENTER) You should read https://docs.oracle.com/javafx/2/layout/size_align.htm for a better understanding

kikio at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.