I am intermediate in Java and fairly new to JavaFX. I'm developing an application that makes use of BorderPane in JavaFX 8. I have two buttons at the bottom of the BorderPane.
- I want to place / align the buttons at the center of the bottom section of the BorderPane, but am not aware of the function that does the job. I was trying with :
Bpane.setAlignment(bttmBttn, Pos.BOTTOM_CENTER)
but didn't work. I want them an the center at all times. It looks like this :
- I want to be able to resize the buttons automatically as the window resizes. As of now the buttons maintain the same gap between themselves as the window is expanded which kind of makes it look like this :
To align the buttons at the center of the bottom section of the BorderPane, an easy and convenient way to do it is to use a HBox as the parent containers of the two buttons.
Since, you want the buttons to expand when you expand the screen, you can make the HGROW for these buttons to
Priority.ALWAYS
.You would also have to remove the
maxSize
constraint from the buttons by calling :There is one small issue with this approach. The buttons will capture the whole available area and we do not want that. An easy way to get rid of it is to add two fixed length, transparent rectangles at the beginning and end of the HBox.
MCVE