1° Step: Create the design in Scene Builder
To make the application responsive, I created an Anchorpane, inside this Anchorpane I inserted a Pane and put as id="PaneTopoTela"
. This Pane (child element) is that I will be able to make responsive from the FXML file.
Step: Insert code into FXML file:
<AnchorPane id="AnchorPane" prefHeight="613.0" prefWidth="748.0" stylesheets="@estilo.css" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplicationteste.FXMLDocumentController">
<children>
<Pane id="PaneTopoTela" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" layoutY="-9.0" prefHeight="92.0" prefWidth="748.0" stylesheets="@estilo.css" />
</children>
</AnchorPane>
Explanation:
Notice that after the id="Panetoptela" I put Anchorpane.leftAnchor="0.0" Anchorpane.rightAnchor="0.0"?
This Anchorpane.right and left will have the same functionality in Javafx as the anchor has in netbeans. It will anchor the elements in wherever you want.
About the anchor in the netbeans layout: Do you know when you right-click a child element in netbeans and it appears to you "Anchor -> Left/Right/Top/Bottom"? So, this is it!
So in Javafx, you have 4 options, they are:
AnchorPane.topAnchor
AnchorPane.bottomAnchor
AnchorPane.leftAnchor
AnchorPane.rightAnchor
If you match the 0.0, as I did... it will align the child element within the Anchorpane.
For more information.
Anchorpane Javafx