There are many duplicate class names between Java Swing and JavaFX. If you import the wrong class, you'll have compiler errors. For example:
Always choose JavaFX import statements. For example, you need the JavaFX version of Color and Button.
If your GUI layout isn't behaving the way you expect it to, try giving each layout container a different temporary background color using setBackground(Background). When you do this, you will be able to see exactly how large each container is. You might be surprised at what you find.
Here's how to add a background color:
HBox myHBox = new HBox();
// Fills the myHBox background with AQUA color
BackgroundFill fill = new BackgroundFill(Color.AQUA, new CornerRadii(2), new Insets(0));
myHBox.setBackground(new Background(fill));
Last modified: March 01, 2023
Back to Building A Gui From Scratch