Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Positioning Buttons Within JavaFX, Margins?

I've been toying around in JavaFX, trying to position buttons in the center of a BorderPane. Because I'm loading the buttons' positions from a text file, I'm looking to modify the positions within the controller at loading time.

It seems that within SceneBuilder, LayoutX and LayoutY aren't moving the button, so I've set the Alignment and edited the margins, which seem to help position them. Thing is, there doesn't seem to be a "setMargin()" method for Buttons: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Button.html

Is there a way I can set the margins of buttons within JavaFX, or should I be positioning them another way? I'm working inside a BorderPane, which may or may not determine why LayoutX/Y (which I assume is the traditional way to position things) isn't working. Thanks!

1 Answer

I figured this out a while ago. Turns out I needed to place a pane inside the particular part of the BorderPane where I needed the buttons in order to position them with LayoutX/Y. Thanks to all who read the question!