Error when trying to use setText() method ( java Fx, sceneBuilder ) - javafx

I am working on a employee management system using java fx and mysql. Basically, when the user click on a row of the tableview, it stock the row data in a employee object, than to String variable. At the same times, an edit scene open. I want the TextField in the new scene to be set up with the previous variable that the row had.
The method displaySelected() is a mouseEvent method, so its in this method that I retrieve row data. Right after retrieving the data, I call switchEdit() method, its only purpose is to open the Edit scene.
*Note that retrieving data from row is working just fine, I print it to be sure.
Right after opening the new scene, I use setText method to set the data in the TextField, thats where the error occurs. I get :
Cannot invoke "javafx.scene.control.TextField.setText(String)" because "this.idEdit" is null
I doubled check, I got all the necessary #FXML import and I checked previous similar question but it didn't help or maybe I didn't know how to implement it in my own code...
I even tried to setText directly in switchEdit method, but I get the same mistakes, and I think the problem may occur because im using one controller on two scene?
I honestly did my best before asking my question, thanks for your help and Ill take any advice on the way I typed my answer so next time Ill be better at helping you to help me.
Board.java class control the dashboard scene and the edit scene :
public class Board {
#FXML
private TableView<employeeList> employee;
#FXML
private TableColumn<employeeList, String> firstColumn;
#FXML
private TableColumn<employeeList, String> genderColumn;
#FXML
private TableColumn<employeeList, String> idColumn;
#FXML
private TableColumn<employeeList, String> lastColumn;
#FXML
private TableColumn<employeeList, String> yoeColumn;
#FXML
private Button refresh;
public ObservableList<employeeList> data = FXCollections.observableArrayList();
public void refreshTable() {
//CLEAN TABLEVIEW BEFORE REFRESH
employee.getItems().clear();
try {
String query = "select * from employee";
DataBase connectLive = new DataBase();
Connection connectDb = connectLive.getConnection();
Statement st;
ResultSet rs;
st = connectDb.createStatement();
rs = st.executeQuery(query);
employeeList emp;
while (rs.next()) {
emp = new employeeList(rs.getInt("id"), rs.getString("firstname"), rs.getString("lastname"), rs.getString("gender"), rs.getString("yoe"));
data.add(emp);
}
connectDb.close();
} catch (Exception e) {
e.printStackTrace();
}
idColumn.setCellValueFactory(new PropertyValueFactory<employeeList, String>("id"));
firstColumn.setCellValueFactory(new PropertyValueFactory<employeeList, String>("firstname"));
lastColumn.setCellValueFactory(new PropertyValueFactory<employeeList, String>("lastname"));
genderColumn.setCellValueFactory(new PropertyValueFactory<employeeList, String>("gender"));
yoeColumn.setCellValueFactory(new PropertyValueFactory<employeeList, String>("yoe"));
employee.setItems(data);
}
public void displaySelected(MouseEvent event) throws IOException {
employeeList emp = employee.getSelectionModel().getSelectedItem();
if (emp ==null) {
System.out.println("Ya R");
}
else {
String f = emp.getFirstname();
String l = emp.getLastname();
String i = String.valueOf(emp.getId());
String g = emp.getGender();
String y = emp.getYoe();
switchEdit();
idEdit.setText(i);
firstnameEdit.setText(f);
lastnameEdit.setText(l);
genderEdit.setText(g);
yoeEdit.setText(y);
// settEdit(f,l,i,g,y);
}
}
//EDIT
#FXML
private Button exitEdit;
#FXML
private Button buttonfinish;
#FXML
private TextField firstnameEdit;
#FXML
private TextField genderEdit;
#FXML
private TextField idEdit;
#FXML
private TextField lastnameEdit;
#FXML
private TextField yoeEdit;
#FXML
private AnchorPane paneEdit;
public void exitEdit(ActionEvent e) {
Stage stage;
stage = (Stage) paneEdit.getScene().getWindow();
stage.close();
}
public void exit() {
Stage stage;
stage = (Stage) paneEdit.getScene().getWindow();
stage.close();
}
public void switchEdit() throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/application/Edit.fxml"));
Scene scene = new Scene(root);
scene.setFill(Color.TRANSPARENT);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
Stage primaryStage = new Stage();
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
}
public void switchE(ActionEvent e) throws IOException {
switchEdit();
}
}
fxml code for the board:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Board">
<children>
<AnchorPane fx:id="pane2" prefHeight="860.0" prefWidth="920.0" style="-fx-background-color: #1B2430;">
<children>
<VBox layoutX="60.0" layoutY="25.0" prefHeight="797.0" prefWidth="777.0" style="-fx-background-color: #EEEEEE; -fx-background-radius: 30;">
<children>
<AnchorPane prefHeight="28.0" prefWidth="777.0">
<children>
<Button fx:id="exitButton" layoutX="734.0" layoutY="20.0" mnemonicParsing="false" onAction="#exit" prefHeight="20.0" prefWidth="20.0" style="-fx-background-radius: 100; -fx-background-color: #7b3733;" text="X" textFill="#eeeeee">
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.5" />
</color>
</DropShadow>
</effect>
<font>
<Font name="Consolas" size="12.0" />
</font>
</Button>
</children>
</AnchorPane>
<HBox alignment="CENTER" prefHeight="119.0" prefWidth="737.0" style="-fx-background-color: #336e7b; -fx-background-radius: 30;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" text="Dash Board" textFill="WHITE">
<font>
<Font name="Calibri Light" size="24.0" />
</font>
<HBox.margin>
<Insets right="30.0" />
</HBox.margin>
</Label>
</children>
<VBox.margin>
<Insets left="20.0" right="20.0" top="20.0" />
</VBox.margin>
</HBox>
<HBox prefHeight="42.0" prefWidth="581.0">
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0" />
<BorderPane prefHeight="38.0" prefWidth="1026.0">
<right>
<TextField prefHeight="25.0" prefWidth="219.0" promptText="🔎 Search keywords" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets right="20.0" />
</BorderPane.margin>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</TextField>
</right>
<left>
<Button fx:id="refresh" mnemonicParsing="false" onAction="#refreshTable" prefHeight="25.0" prefWidth="82.0" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;" text="🗘" textFill="WHITE" textOverrun="CLIP" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="2.0" left="20.0" />
</BorderPane.margin>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</Button>
</left>
</BorderPane>
</children>
</HBox>
<BorderPane prefHeight="364.0" prefWidth="777.0">
<center>
<TableView fx:id="employee" onMouseClicked="#displaySelected" prefHeight="345.0" prefWidth="737.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="idColumn" prefWidth="84.0" text="ID" />
<TableColumn fx:id="firstColumn" prefWidth="163.0" text="First Name" />
<TableColumn fx:id="lastColumn" prefWidth="163.0" text="Last Name" />
<TableColumn fx:id="genderColumn" prefWidth="163.0" text="Gender" />
<TableColumn fx:id="yoeColumn" prefWidth="163.0" text="Year Of Experience" />
</columns>
<BorderPane.margin>
<Insets left="20.0" right="20.0" />
</BorderPane.margin>
</TableView>
</center>
</BorderPane>
<BorderPane prefHeight="60.0" prefWidth="777.0">
<left>
<Button fx:id="addButton" mnemonicParsing="false" onAction="#addButton" prefHeight="25.0" prefWidth="200.0" style="-fx-background-color: #336e7b; -fx-background-radius: 30;" text="Add" textFill="WHITE" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets left="20.0" right="20.0" />
</BorderPane.margin>
<font>
<Font name="Calibri" size="18.0" />
</font>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.5" />
</color></DropShadow>
</effect>
</Button>
</left>
<right>
<Button fx:id="deleteButton" mnemonicParsing="false" onAction="#switchD" prefWidth="200.0" style="-fx-background-color: #7b3733; -fx-background-radius: 30;" text="Delete" textFill="WHITE" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets left="20.0" right="20.0" />
</BorderPane.margin>
<font>
<Font name="Calibri" size="18.0" />
</font>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.5" />
</color></DropShadow>
</effect>
</Button>
</right>
<center>
<Button fx:id="EditButton" mnemonicParsing="false" onAction="#switchE" prefHeight="25.0" prefWidth="200.0" style="-fx-background-color: #808080; -fx-background-radius: 30;" text="Edit" textFill="WHITE" BorderPane.alignment="CENTER">
<font>
<Font name="Calibri" size="18.0" />
</font>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.5" />
</color></DropShadow>
</effect>
</Button>
</center>
</BorderPane>
<BorderPane prefHeight="57.0" prefWidth="777.0">
<VBox.margin>
<Insets top="90.0" />
</VBox.margin>
<center>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Copyright © 2022 - Amine Lakhal - Raphael Ducros" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</children>
</VBox>
</children>
</AnchorPane>
</children>
</AnchorPane>
fxml code for the edit page
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:id="paneEdit" prefHeight="775.0" prefWidth="493.0" style="-fx-background-color: #1B2430;" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Board">
<children>
<VBox layoutX="65.0" layoutY="30.0" prefHeight="715.0" prefWidth="364.0" style="-fx-background-color: #EEEEEE; -fx-background-radius: 30;">
<children>
<Button fx:id="exitEdit" mnemonicParsing="false" onAction="#exitEdit" prefHeight="20.0" prefWidth="20.0" style="-fx-background-radius: 100; -fx-background-color: #7b3733;" text="X" textFill="#eeeeee">
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.5" />
</color>
</DropShadow>
</effect>
<font>
<Font name="Consolas" size="12.0" />
</font>
<VBox.margin>
<Insets left="328.0" top="13.0" />
</VBox.margin>
</Button>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="359.0" style="-fx-background-color: #336e7b; -fx-background-radius: 30;">
<children>
<ImageView>
<image>
<Image url="#edit.png" />
</image>
</ImageView>
<Label alignment="CENTER" contentDisplay="CENTER" text=" Edit Employee" textFill="WHITE">
<font>
<Font name="Calibri Light" size="24.0" />
</font>
<HBox.margin>
<Insets right="30.0" />
</HBox.margin>
</Label>
</children>
<VBox.margin>
<Insets left="20.0" right="20.0" top="20.0" />
</VBox.margin>
</HBox>
<Label prefHeight="35.0" prefWidth="314.0" text="ID Employe *" textFill="#8a959a">
<font>
<Font name="Calibri Italic" size="14.0" />
</font>
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
</Label>
<TextField fx:id="idEdit" prefHeight="35.0" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;">
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
<font>
<Font name="Consolas" size="12.0" />
</font>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</TextField>
<Label prefHeight="35.0" prefWidth="314.0" text="Last Name" textFill="#8a959a">
<VBox.margin>
<Insets left="20.0" right="20.0" top="10.0" />
</VBox.margin>
<font>
<Font name="Calibri Italic" size="14.0" />
</font>
</Label>
<TextField fx:id="lastnameEdit" prefHeight="35.0" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;">
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</TextField>
<Label prefHeight="35.0" prefWidth="473.0" text="First Name" textFill="#8a959a">
<VBox.margin>
<Insets left="20.0" right="20.0" top="15.0" />
</VBox.margin>
<font>
<Font name="Calibri Italic" size="14.0" />
</font>
</Label>
<TextField fx:id="firstnameEdit" prefHeight="35.0" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;">
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</TextField>
<Label prefHeight="35.0" prefWidth="311.0" text="Gender " textFill="#8a959a">
<VBox.margin>
<Insets left="20.0" right="20.0" top="15.0" />
</VBox.margin>
<font>
<Font name="Calibri Italic" size="14.0" />
</font>
</Label>
<TextField fx:id="genderEdit" prefHeight="35.0" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;">
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</TextField>
<Label prefHeight="35.0" prefWidth="318.0" text="Year Of Experience" textFill="#8a959a">
<VBox.margin>
<Insets left="20.0" right="20.0" top="15.0" />
</VBox.margin>
<font>
<Font name="Calibri Italic" size="14.0" />
</font>
</Label>
<TextField fx:id="yoeEdit" prefHeight="35.0" style="-fx-background-radius: 30; -fx-background-color: #D3D3D3;">
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.30000001192092896" />
</color>
</DropShadow>
</effect>
</TextField>
<Label prefHeight="15.0" prefWidth="310.0" text=" Information can be modified later" textFill="#8a959a">
<VBox.margin>
<Insets left="20.0" top="5.0" />
</VBox.margin>
<font>
<Font name="Calibri" size="11.0" />
</font>
</Label>
<HBox prefHeight="35.0" prefWidth="200.0">
<children>
<CheckBox mnemonicParsing="false" text="All data have been confirmed by manager" textFill="#8a959a">
<HBox.margin>
<Insets left="20.0" top="5.0" />
</HBox.margin>
<font>
<Font name="Calibri Italic" size="14.0" />
</font>
</CheckBox>
</children>
</HBox>
<Button fx:id="buttonfinish" mnemonicParsing="false" prefHeight="47.0" prefWidth="359.0" style="-fx-background-radius: 30; -fx-background-color: #336e7b;" stylesheets="#application.css" text="Finish" textFill="WHITE">
<VBox.margin>
<Insets left="20.0" right="20.0" />
</VBox.margin>
<font>
<Font name="Calibri Light" size="18.0" />
</font>
<effect>
<DropShadow offsetY="5.0">
<color>
<Color opacity="0.5" />
</color>
</DropShadow>
</effect>
</Button>
<Text fill="#8a959a" strokeType="OUTSIDE" strokeWidth="0.0" text="All sensitive data are subject to confidentiality rules in force in the province of Quebec. Any illegal use will be punished by law. 23:788:22|667" wrappingWidth="297.13671875">
<VBox.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="10.0" />
</VBox.margin>
<font>
<Font name="Calibri" size="11.0" />
</font>
</Text>
</children>
</VBox>
</children>
</AnchorPane>

Don't use the same controller class (application.Board) for different FXML files.
Each time you load the FXML, the loader will create a new instance of the controller class, only initializing the FXML fields associated with the new FXML fields in the new controller instance.
In your case, the idEdit field is initialized in the controller instance created by the FXML Loader invoked in your switchEdit() method. But that instance differs from the instance that called the switchEdit() method.
Instead, create a new class to form the controller for the employee data editor.
Use MVC to share a model or pass parameters to the new controller. In your case, the shared model or parameters to pass would be the id or data of the selected employee.
The Makery JavaFX tutorial provides an illustrative example.

Related

JavaFx: about nodes and scenes [duplicate]

This question already has an answer here:
How to bind Pane with another Pane in JavaFX
(1 answer)
Closed 3 years ago.
I have a problem with my project I have a stackpane that calls an fxml but my fxml gets bugged:
my fxml main:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ControllerHome">
<children>
<VBox layoutX="10.0" layoutY="10.0" maxWidth="-Infinity" prefWidth="150.0" style="-fx-background-color: #150;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="80.0" prefWidth="150.0" style="-fx-background-color: #0fbcf9;">
<children>
<FontAwesomeIconView fill="WHITE" glyphName="HOME" size="30" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksand; -fx-font-weight: bold; -fx-fill: white;" text="Application">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</HBox>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<VBox.margin>
<Insets top="40.0" />
</VBox.margin>
<children>
<FontAwesomeIconView fx:id="iconUser" glyphName="USERS" onMouseClicked="#xx" size="25" />
<Text fx:id="textUser" onMouseClicked="#xx" strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Usuarios">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
</HBox>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<FontAwesomeIconView glyphName="LIST" size="25" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Requisições">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</HBox>
<VBox alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
<children>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<FontAwesomeIconView glyphName="COG" size="25" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Settings">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
</HBox>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<FontAwesomeIconView glyphName="SIGN_OUT" size="25" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Logout">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
</HBox>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
<padding>
<Insets bottom="20.0" />
</padding>
</VBox>
</children>
</VBox>
<HBox fx:id="subRoot" maxHeight="-Infinity" prefHeight="80.0" style="-fx-background-color: #000;" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<StackPane fx:id="mainRoot" layoutX="265.0" layoutY="256.0" prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: #fff;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0" />
</children>
</AnchorPane>
my controller:
public class ControllerHome implements Initializable {
#FXML
private HBox subRoot;
#FXML
private FontAwesomeIconView iconUser;
#FXML
private Text textUser;
#FXML
private StackPane mainRoot;
#FXML
void xx(MouseEvent event) throws IOException {
System.out.println("xd");
Pane content = FXMLLoader.load(getClass().getResource("mainContentUser.fxml"));
mainRoot.getChildren().addAll(content);
}
#Override
public void initialize(URL location, ResourceBundle resources) {
/*
iconUser.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
System.out.println("xd");
});
textUser.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
System.out.println("xd");
});*/
try {
HBox menu = FXMLLoader.load(getClass().getResource("menuUser.fxml"));
subRoot.getChildren().addAll(menu);
System.out.println("xdxx");
} catch (IOException ex) {
Logger.getLogger(ControllerHome.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
my fxml with anchor Pane:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="559.0" prefWidth="811.0" style="-fx-background-color: #f547;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button layoutX="388.0" layoutY="199.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
I don't know what is going on it is not full size and is covering other parts of my screen
I don't know if it's because of the stackpane or some configuration I made.
If anyone can help me on how I can solve this
Your main problem is misusing different Pane types to achive your goal. It would be very hard to point out all the problems this layout has. That is why I publish fxml which provides expected layout. Load it in SceneBuilder and try to manipulate it for better understanding. Remember that order of addition to GridPane (same for every Pane) affects z-order of children.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="10.0" prefWidth="200.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="-Infinity" minHeight="-Infinity" prefHeight="100.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="-Infinity" prefHeight="200.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox style="-fx-background-color: green;" GridPane.rowIndex="1">
<children>
<VBox VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</VBox>
<VBox alignment="BOTTOM_LEFT" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</VBox>
</children>
</VBox>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: pink;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</StackPane>
<HBox alignment="CENTER_LEFT" spacing="16.0" style="-fx-background-color: black;" GridPane.columnIndex="1">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
<padding>
<Insets left="16.0" />
</padding>
</HBox>
<StackPane style="-fx-background-color: lightblue;" />
</children>
</GridPane>

How can I do dynamic layouts in Javafx?

First of all, excuse me if my English is bad, I don't speak English.
So, I'm working with javafx, when I say "dynamic layouts", I refer to the fact that I have my .fxml already programmed with a default structure which it is so.
menu.fxml view
and its code is this
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import java.lang.String?>
<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefWidth="356.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox prefHeight="243.0" prefWidth="356.0" spacing="2.0" stylesheets="#../styles/Containers.css" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<AnchorPane prefHeight="31.0" prefWidth="356.0">
<children>
<HBox prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<children>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
<image>
<Image url="#../icons/icons8_Calendar_100px.png" />
</image>
</ImageView>
<Label fx:id="lblFecha" prefHeight="31.0" prefWidth="306.0" stylesheets="#../styles/Strings.css" text="---- ----, -----">
<HBox.margin>
<Insets left="15.0" />
</HBox.margin>
<styleClass>
<String fx:value="h4" />
<String fx:value="principal" />
</styleClass>
</Label>
</children>
</HBox>
</children>
</AnchorPane>
<AnchorPane>
<children>
<HBox prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../icons/icons8_Clock_100px.png" />
</image>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</ImageView>
<Label fx:id="lblHora" prefHeight="31.0" prefWidth="306.0" stylesheets="#../styles/Strings.css" text="-- : -- : -- --">
<HBox.margin>
<Insets left="15.0" />
</HBox.margin>
<styleClass>
<String fx:value="h4" />
<String fx:value="principal" />
</styleClass>
</Label>
</children>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
</HBox>
</children>
</AnchorPane>
<AnchorPane fx:id="opcParlking">
<children>
<JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" onAction="#openParking" prefHeight="35.0" prefWidth="366.0" styleClass="h4" text="Parking" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="#../icons/icons8_Tollbooth_100px.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<stylesheets>
<URL value="#../styles/Buttons.css" />
<URL value="#../styles/Strings.css" />
</stylesheets>
</JFXButton>
</children>
</AnchorPane>
<AnchorPane>
<children>
<JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="363.0" styleClass="h4" text="Tipo de vehiculos" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="#../icons/icons8_Traffic_Jam_96px.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<stylesheets>
<URL value="#../styles/Buttons.css" />
<URL value="#../styles/Strings.css" />
</stylesheets>
</JFXButton>
</children>
</AnchorPane>
<AnchorPane>
<children>
<JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="363.0" styleClass="h4" text="Usuarios" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="#../icons/icons8_User_Groups_100px.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<stylesheets>
<URL value="#../styles/Buttons.css" />
<URL value="#../styles/Strings.css" />
</stylesheets>
</JFXButton>
</children>
</AnchorPane>
<AnchorPane>
<children>
<JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="361.0" styleClass="h4" text="Clientes" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="#../icons/icons8_Helping_Hand_104px.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<stylesheets>
<URL value="#../styles/Buttons.css" />
<URL value="#../styles/Strings.css" />
</stylesheets>
</JFXButton>
</children>
</AnchorPane>
<AnchorPane>
<children>
<JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="361.0" styleClass="h4" text="Reportes" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="#../icons/icons8_Combo_Chart_104px.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<stylesheets>
<URL value="#../styles/Buttons.css" />
<URL value="#../styles/Strings.css" />
</stylesheets>
</JFXButton>
</children>
</AnchorPane>
<AnchorPane>
<children>
<JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="29.0" prefWidth="356.0" styleClass="h4" text="Configuraciones" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<graphic>
<ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="#../icons/icons8_Automation_100px.png" />
</image>
</ImageView>
</graphic>
<font>
<Font name="System Bold" size="12.0" />
</font>
<padding>
<Insets bottom="8.0" top="8.0" />
</padding>
<stylesheets>
<URL value="#../styles/Buttons.css" />
<URL value="#../styles/Strings.css" />
</stylesheets>
</JFXButton>
</children>
</AnchorPane>
</children>
</VBox>
</children>
</AnchorPane>
I want to be able in my execution time to hide any buttons and that the buttons adjust automatically filling the blank space that the hidden button leaves.
I've tried using in the MenuController.java instructions like opcParlking.setVisible(false) but it leave me a blank space. This the picture imagen 2.
How can I fix this?
You will want to assign an fx:id to your VBox as well and then inject it into your controller:
#FXML
private VBox vBox;
Then, in your controller, instead of setting a node visible or not, just remove it from the VBox:
vBox.getChildren().remove(opcParlking);
This will remove the node entirely, instead of just making it invisible. Therefore, you will not have the empty space.

Javafx Scenebuilder preview not matching actual scene

When I preview my form inside the Scene builder preview window (Window in preview mode) option everything is laid out perfectly like I want it and it is a good size. When I actually run the program (what actually is shown) and click on my button to open this new form, only about 1/4 of my labels and buttons are actually shown unless I make it full screen and everything is far more spaced out than it should be. Anyway advice to fix this?
`
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="sample.Controller">
<children>
<VBox layoutY="-5.0" prefHeight="811.0" prefWidth="1058.0" spacing="15.0">
<children>
<VBox prefHeight="301.0" prefWidth="488.0" spacing="20.0">
<children>
<Label alignment="TOP_CENTER" contentDisplay="CENTER" text="These are the available options for a 7 day cruise">
<font>
<Font name="System Bold" size="30.0" />
</font>
</Label>
<RadioButton mnemonicParsing="false" text="Interior room ticket $765" />
<RadioButton mnemonicParsing="false" text="Ocean view ticket $810" />
<RadioButton mnemonicParsing="false" text="Balcony ticket $1090" />
<RadioButton mnemonicParsing="false" text="Suite ticket $1560">
<padding>
<Insets top="5.0" />
</padding>
</RadioButton>
<Label text="*Prices shown are prices per person">
<font>
<Font name="System Bold Italic" size="24.0" />
</font>
</Label>
</children>
<padding>
<Insets top="20.0" />
</padding>
</VBox>
<HBox prefHeight="41.0" prefWidth="1895.0" spacing="30.0">
<children>
<CheckBox mnemonicParsing="false" text="VIP discount" />
<CheckBox mnemonicParsing="false" text="Prepaid gratitude" />
</children>
</HBox>
<Label text="Prepaid activites that can be attended by both guests">
<font>
<Font name="System Bold" size="30.0" />
</font>
<padding>
<Insets top="75.0" />
</padding>
</Label>
<HBox prefHeight="314.0" prefWidth="1895.0">
<children>
<VBox prefHeight="419.0" prefWidth="922.0" spacing="20.0">
<children>
<CheckBox mnemonicParsing="false" text="Free Internet" />
<CheckBox mnemonicParsing="false" text="Couples massage" />
<CheckBox mnemonicParsing="false" text="Horse back riding excursion" />
<CheckBox mnemonicParsing="false" text="Fitness Classes" />
<CheckBox mnemonicParsing="false" />
</children>
</VBox>
<VBox prefHeight="477.0" prefWidth="942.0" spacing="20.0">
<children>
<CheckBox mnemonicParsing="false" />
<CheckBox mnemonicParsing="false" />
<CheckBox mnemonicParsing="false" text="Casino Games" />
<CheckBox mnemonicParsing="false" text="Watch a show at the theatre" />
<CheckBox mnemonicParsing="false" text="Game Show" />
</children>
<padding>
<Insets bottom="25.0" />
</padding>
</VBox>
</children>
</HBox>
<Button mnemonicParsing="false" text="Calculate total price" />
</children>
<padding>
<Insets bottom="10.0" left="20.0" />
</padding>
</VBox>
</children>
</AnchorPane>
`
Main Class
I went in and got rid of most of the manual sizes. I would also set the PrimaryStage width to 800 and height to 700 and not allow resizing. Test this out.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="700.0" maxWidth="800.0" minHeight="700.0" minWidth="800.0" prefHeight="700.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<VBox layoutY="-5.0" spacing="15.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox maxHeight="-Infinity" spacing="20.0" VBox.vgrow="ALWAYS">
<children>
<Label alignment="TOP_CENTER" contentDisplay="CENTER" text="These are the available options for a 7 day cruise">
<font>
<Font name="System Bold" size="22.0" />
</font>
</Label>
<RadioButton mnemonicParsing="false" text="Interior room ticket $765">
<font>
<Font size="18.0" />
</font>
<padding>
<Insets left="10.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Ocean view ticket $810">
<font>
<Font size="18.0" />
</font>
<padding>
<Insets left="10.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Balcony ticket $1090">
<font>
<Font size="18.0" />
</font>
<padding>
<Insets left="10.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Suite ticket $1560">
<padding>
<Insets left="10.0" />
</padding>
<font>
<Font size="18.0" />
</font>
</RadioButton>
</children>
</VBox>
<VBox>
<children>
<Label text="*Prices shown are prices per person">
<font>
<Font name="System Bold Italic" size="16.0" />
</font>
</Label>
<HBox spacing="30.0">
<children>
<CheckBox mnemonicParsing="false" text="VIP discount">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Prepaid gratitude">
<font>
<Font size="15.0" />
</font>
</CheckBox>
</children>
<padding>
<Insets left="10.0" />
</padding>
</HBox>
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="20.0" VBox.vgrow="ALWAYS">
<children>
<Label text="Prepaid activites that can be attended by both guests" VBox.vgrow="ALWAYS">
<font>
<Font name="System Bold" size="22.0" />
</font>
</Label>
<HBox VBox.vgrow="ALWAYS">
<children>
<VBox spacing="20.0" HBox.hgrow="ALWAYS">
<children>
<CheckBox mnemonicParsing="false" text="Free Internet">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Couples massage">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Horse back riding excursion">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Fitness Classes">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false">
<font>
<Font size="15.0" />
</font>
</CheckBox>
</children>
<padding>
<Insets left="10.0" />
</padding>
</VBox>
<VBox spacing="20.0" HBox.hgrow="ALWAYS">
<children>
<CheckBox mnemonicParsing="false">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Casino Games">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Watch a show at the theatre">
<font>
<Font size="15.0" />
</font>
</CheckBox>
<CheckBox mnemonicParsing="false" text="Game Show">
<font>
<Font size="15.0" />
</font>
</CheckBox>
</children>
<padding>
<Insets bottom="25.0" />
</padding>
</VBox>
</children>
</HBox>
</children>
<VBox.margin>
<Insets top="30.0" />
</VBox.margin>
</VBox>
<Button mnemonicParsing="false" prefHeight="40.0" text="Calculate total price" />
</children>
<padding>
<Insets bottom="15.0" left="20.0" />
</padding>
</VBox>
</children>
<padding>
<Insets top="15.0" />
</padding>
</AnchorPane>

having trouble with javafx program

I am in the process of creating a javafx desktop application. The problem I'm encountering is if I add a controller to my fxml files the controls dissapear somehow. The program uses a fade transition to switch between the fxml files
AnchorPane reorderLevels,purchaseorder,onlineSales,generalLedger
,cashBook,payments,departmentalTransfers
,purchaseInvoice
,productMantainance,
branchTransfers,stockMovement,invoiceRegistration,stockTake;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Override
public void initialize(URL url, ResourceBundle rb) {
//load all the fxml screens when the buttons are clicked
try {
//screens for the application
reorderLevels = FXMLLoader.load(getClass().getResource("ReorderLevels.fxml"));
purchaseorder = FXMLLoader.load(getClass().getResource("PurchaseOrder.fxml"));
onlineSales = FXMLLoader.load(getClass().getResource("OnlineSales.fxml"));
generalLedger = FXMLLoader.load(getClass().getResource("GeneralLedger.fxml"));
cashBook = FXMLLoader.load(getClass().getResource("CashBook.fxml"));
departmentalTransfers = FXMLLoader.load(getClass().getResource("DepartmentalTransfers.fxml"));
purchaseInvoice = FXMLLoader.load(getClass().getResource("PurchaseInvoice.fxml"));
productMantainance = FXMLLoader.load(getClass().getResource("ProductMantainance.fxml"));
branchTransfers = FXMLLoader.load(getClass().getResource("BranchTransfers.fxml"));
stockMovement = FXMLLoader.load(getClass().getResource("StockMovement.fxml"));
payments = FXMLLoader.load(getClass().getResource("Payments.fxml"));
invoiceRegistration = FXMLLoader.load(getClass().getResource("InvoiceRegistration.fxml"));
stockTake = FXMLLoader.load(getClass().getResource("StockTake.fxml"));
//set each and every individual node when the buttons are clicked
setNode(reorderLevels);
} catch (IOException ex) {
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void setNode(Node node) {
holderPane.getChildren().clear();
holderPane.getChildren().add((Node) node);
//the transition between the screens
FadeTransition ft = new FadeTransition(Duration.millis(1));
ft.setNode(node);
ft.setFromValue(0.1);
ft.setToValue(1);
ft.setCycleCount(1);
ft.setAutoReverse(false);
ft.play();
}
/* screens */
#FXML
private void switchReorderLevels(ActionEvent event) {
setNode(reorderLevels);
}
#FXML
private void switchOnlineSales(ActionEvent event) {
setNode(onlineSales);
}
#FXML
private void switchGeneralLedger(ActionEvent event) {
setNode(generalLedger);
}
#FXML
private void switchPurchaseOrder(ActionEvent event) {
setNode(purchaseorder);
}
#FXML
private void switchCashBook(ActionEvent event) {
setNode(cashBook);
}
#FXML
private void switchAlert(ActionEvent event) {
setNode(purchaseorder);
}
#FXML
private void switchPayments(ActionEvent event) {
setNode(payments);
}
#FXML
private void switchDepartmentalTransfers(ActionEvent event) {
setNode(departmentalTransfers);
}
#FXML
private void switchPurchaseInvoice(ActionEvent event) {
setNode(purchaseInvoice);
}
#FXML
private void switchProductMantainance(ActionEvent event) {
setNode(productMantainance);
}
#FXML
private void switchBranchTransfers(ActionEvent event) {
setNode(branchTransfers);
}
//this is a screen that will displayone of the layouts that will show re order levels
<AnchorPane id="AnchorPane" prefHeight="713.0" prefWidth="1219.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="24.0" layoutY="17.0" prefHeight="30.0" prefWidth="285.0" style="-fx-font-size: 20; -fx-font-weight: bold; -fx-text-fill: #7387A8;" text="ReOrder Levels" />
<Separator layoutX="25.0" layoutY="54.0" prefHeight="5.0" prefWidth="1191.0" />
<Pane fx:id="tbl_reorderLevels" layoutX="25.0" layoutY="108.0" prefHeight="413.0" prefWidth="1174.0" style="-fx-background-color: #EFEFEF;">
<children>
<JFXComboBox fx:id="cmd_reOrder_productCode" layoutX="48.0" layoutY="33.0" prefHeight="25.0" prefWidth="267.0" promptText="Product Code" />
<JFXTextField fx:id="txt_reOrder_reorderLevel" labelFloat="true" layoutX="48.0" layoutY="91.0" prefHeight="25.0" prefWidth="267.0" promptText="Reorder Level" />
//this is the root layout that has buttons that will navigate between the screens using a fade transition
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<!-- root layout -->
<AnchorPane id="AnchorPane" nodeOrientation="LEFT_TO_RIGHT" prefHeight="623.0" prefWidth="1271.0" style="-fx-background-color: #fff;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller = "dashboard.FXMLDocumentController">
<children>
<Pane layoutX="-2.0" prefHeight="81.0" prefWidth="1272.0" style="-fx-background-color: #0b8dee;" styleClass="head-background" stylesheets="#style.css" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="labelEstock" layoutX="204.0" layoutY="-3.0" prefHeight="88.0" prefWidth="536.0" style="-fx-shape: round;" stylesheets="#custom.css" text="Oasys Estock" textFill="WHITE">
<font>
<Font name="Brush Script MT Italic" size="36.0" />
</font>
</Label>
<!-- <ImageView fx:id="imageEstock" fitHeight="110.0" fitWidth="92.0" layoutX="102.0" layoutY="8.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image
url="#../../../../AndroidStudioProjects/OasysEstock/app/src/main/res/drawable/fortified_icon.png" />
</image>
</ImageView> -->
</children>
</Pane>
<VBox layoutY="85.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="518.0" prefWidth="122.0" style="-fx-background-color: #0b8dee; -fx-background-radius: 15;">
<children>
<JFXButton id="btnReorderLevels" fx:id="btnReorderLevels" buttonType="RAISED" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onAction="#switchReorderLevels" prefHeight="47.0" prefWidth="107.0" style="-fx-background-radius: 100;" text="ReOrder Levels" textFill="#f5f0f0">
<VBox.margin>
<Insets />
</VBox.margin>
<font>
<Font name="Calibri" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnInvoiceRegistration" onAction="#switchInvoiceRegistration" prefHeight="25.0" prefWidth="121.0" text="Invoice Registration" textFill="#f8f4f4" />
<JFXButton fx:id="btnPurchaseOrder" buttonType="RAISED" onAction="#switchPurchaseOrder" prefHeight="34.0" prefWidth="107.0" text="Purchase Order" textFill="#f5f0f0">
<font>
<Font name="Cambria" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnOnlineSales" onAction="#switchOnlineSales" prefHeight="39.0" prefWidth="107.0" text="Online Sales" textFill="#fff9f9">
<font>
<Font name="Calibri" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnGeneralLedger" onAction="#switchGeneralLedger" prefHeight="40.0" prefWidth="108.0" text="General Ledger" textFill="#f2eeee" />
<JFXButton fx:id="btnCashBook" onAction="#switchCashBook" prefHeight="35.0" prefWidth="104.0" text="Cash Book" textFill="#fffefe" />
<JFXButton fx:id="btnPayments" buttonType="RAISED" onAction="#switchPayments" prefHeight="25.0" prefWidth="114.0" text="Payments" textFill="#fcf6f6" />
<JFXButton fx:id="btnDepartmentalTransfers" buttonType="RAISED" layoutX="10.0" layoutY="205.0" onAction="#switchDepartmentalTransfers" prefHeight="25.0" prefWidth="114.0" text="Dept Transfers" textFill="#fcf6f6" />
<JFXButton fx:id="btnProductMantainance" buttonType="RAISED" layoutX="10.0" layoutY="230.0" onAction="#switchProductMantainance" prefHeight="56.0" prefWidth="121.0" text="Product Mantainance" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnPurchaseInvoice" buttonType="RAISED" layoutX="10.0" layoutY="255.0" onAction="#switchPurchaseInvoice" prefHeight="56.0" prefWidth="121.0" text="Purchase Invoice" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnBranchTransfers" buttonType="RAISED" layoutX="10.0" layoutY="311.0" onAction="#switchBranchTransfers" prefHeight="56.0" prefWidth="121.0" text="Branch Transfers" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnStockMovement" buttonType="RAISED" layoutX="10.0" layoutY="367.0" onAction="#switchStockMovement" prefHeight="56.0" prefWidth="121.0" text="Stock Movement" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnStockTake" buttonType="RAISED" layoutX="10.0" layoutY="448.0" onAction="#switchStockTake" prefHeight="56.0" prefWidth="121.0" text="Stock Take" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
</children>
<effect>
<InnerShadow blurType="TWO_PASS_BOX" choke="0.58" color="#212122" height="26.69" radius="10.620000000000001" width="17.79" />
</effect>
</VBox>
<AnchorPane fx:id="holderPane" layoutX="125.0" layoutY="96.0" prefHeight="507.0" prefWidth="1134.0"/>
</children>
</AnchorPane>

Scene Builder cannot load my fxml file though it gives no error

I get no error loading up fxml from Java code.
I went through previous posts and tried solutions mentioned but didn't found a fix yet.
My fxml was working fine so far.
But I tweaked something and Scene Builder doesn't give any error but it won't render my fxml file when I preview it in Scene Builder and all I see is a blank white screen.
Here is code of fxml file below:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.effect.Blend?>
<?import javafx.scene.effect.Bloom?>
<?import javafx.scene.effect.ColorAdjust?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.effect.Glow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<AnchorPane id="customerAnchorPane" fx:id="customerAnchorPane" blendMode="OVERLAY" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: gray; -fx-border-color: gray;" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane id="login" fx:id="login" layoutX="2.0" layoutY="2.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="398.0" prefWidth="600.0" style="-fx-background-color: gray;" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="-1.0" AnchorPane.topAnchor="1.0">
<left>
<Pane id="customerLabels_pane" fx:id="customerLabels_pane" prefHeight="299.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Label id="customerfName_label" fx:id="customerfName_label" alignment="CENTER" contentDisplay="CENTER" layoutX="46.0" layoutY="101.0" prefHeight="35.0" prefWidth="109.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="First Name" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="15.0" right="8.0" top="5.0" />
</padding>
</Label>
<Label id="customerlName_label" fx:id="customerlName_label" alignment="CENTER" contentDisplay="CENTER" layoutX="46.0" layoutY="147.0" prefHeight="35.0" prefWidth="109.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Last Name" textAlignment="CENTER" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
<Label id="customerEmail_label1" fx:id="customerEmail_label1" alignment="CENTER" contentDisplay="CENTER" layoutX="46.0" layoutY="189.0" prefHeight="35.0" prefWidth="109.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Email" textAlignment="CENTER" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="15.0" right="8.0" top="5.0" />
</padding>
</Label>
<Label id="customerAddress_label" fx:id="customerAddress_label" alignment="CENTER" contentDisplay="CENTER" layoutX="46.0" layoutY="238.0" prefHeight="35.0" prefWidth="109.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Address" textAlignment="CENTER" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="15.0" right="8.0" top="5.0" />
</padding>
</Label>
<Label id="customerUsername_label" fx:id="customerUsername_label" alignment="CENTER" contentDisplay="CENTER" layoutX="46.0" layoutY="14.0" prefHeight="35.0" prefWidth="109.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Username" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="15.0" right="8.0" top="5.0" />
</padding>
</Label>
<Label id="customerPassword_label" fx:id="customerPassword_label" alignment="CENTER" contentDisplay="CENTER" layoutX="46.0" layoutY="56.0" prefHeight="35.0" prefWidth="109.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Password" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<padding>
<Insets bottom="5.0" left="15.0" right="8.0" top="5.0" />
</padding>
</Label>
</children>
</Pane>
</left>
<center>
<Pane id="signUptFields_pane" fx:id="signUptFields_pane" prefHeight="308.0" prefWidth="397.0" BorderPane.alignment="CENTER">
<children>
<TextField id="customerUsername_tField" fx:id="customerUsername_tField" alignment="CENTER" layoutX="14.0" layoutY="14.0" prefHeight="35.0" prefWidth="230.0" promptText="Enter username here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
<tooltip>
<Tooltip id="usernameToolTip" fx:id="usernameToolTip" autoHide="true" contentDisplay="CENTER" text="Do not enter special characters or spaces" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
</Tooltip>
</tooltip>
</TextField>
<PasswordField id="customerPassword_tField" fx:id="customerPassword_tField" alignment="CENTER" layoutX="14.0" layoutY="59.0" prefHeight="35.0" prefWidth="230.0" promptText="Enter password here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
</PasswordField>
<TextField id="customerfName_tField" fx:id="customerfName_tField" alignment="CENTER" layoutX="14.0" layoutY="102.0" prefHeight="35.0" prefWidth="230.0" promptText="Enter first name here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
<tooltip>
<Tooltip id="fNameToolTip" fx:id="fNameToolTip" contentDisplay="CENTER" text="Enter only characters, no spaces allowed" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
</Tooltip>
</tooltip>
</TextField>
<TextField id="customerlName_tField" fx:id="customerlName_tField" accessibleRole="TEXT_FIELD" alignment="CENTER" layoutX="14.0" layoutY="146.0" prefHeight="35.0" prefWidth="230.0" promptText="Enter last name here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
<tooltip>
<Tooltip id="lNameToolTip" fx:id="lNameToolTip" contentDisplay="CENTER" text="Enter only characters, no spaces allowed" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
</Tooltip>
</tooltip>
</TextField>
<TextField id="customerEmail_tField" fx:id="customerEmail_tField" accessibleRole="TEXT_FIELD" alignment="CENTER" layoutX="14.0" layoutY="188.0" prefHeight="35.0" prefWidth="230.0" promptText="Enter email address here" style="-fx-background-color: gray;">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<effect>
<Glow />
</effect>
<tooltip>
<Tooltip id="emailToolTip" fx:id="emailToolTip" contentDisplay="CENTER" text="Format: abc#xyz.com" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
</Tooltip>
</tooltip>
</TextField>
<TextArea id="customerAddress_tArea" fx:id="customerAddress_tArea" layoutX="14.0" layoutY="236.0" prefHeight="42.0" prefWidth="230.0" promptText="Enter address here" style="-fx-background-color: gray; -fx-border-color: gray;" wrapText="true">
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<effect>
<ColorAdjust brightness="0.33" contrast="0.02" hue="0.12" saturation="-0.07">
<input>
<DropShadow />
</input>
</ColorAdjust>
</effect>
<font>
<Font name="Courier Oblique" size="14.0" />
</font>
<padding>
<Insets bottom="0.5" left="0.5" right="0.5" top="0.5" />
</padding>
<tooltip>
<Tooltip id="addressToolTip" fx:id="addressToolTip" contentDisplay="CENTER" text="Do not enter any special characters" textAlignment="CENTER">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
</Tooltip>
</tooltip>
</TextArea>
<Button id="customerSubmit_Button" fx:id="customerSubmit_Button" alignment="CENTER" contentDisplay="RIGHT" layoutX="149.0" layoutY="294.0" mnemonicParsing="false" prefHeight="35.0" prefWidth="95.0" style="-fx-background-color: wheat; -fx-border-color: brown;" text="Submit" textAlignment="CENTER" textFill="#081057">
<font>
<Font name="Wawati SC Regular" size="16.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<Label id="lblInvalidfName" fx:id="lblInvalidfName" alignment="CENTER" contentDisplay="CENTER" layoutX="251.0" layoutY="102.0" prefHeight="17.0" prefWidth="120.0" style="-fx-background-color: black; -fx-border-color: black;" text="Invalid First Name" textAlignment="CENTER" textFill="#d72323" textOverrun="CENTER_ELLIPSIS" visible="false">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<effect>
<Bloom threshold="0.22" />
</effect>
<cursor>
<Cursor fx:constant="DISAPPEAR" />
</cursor>
</Label>
<Label id="lblInvalidlName" fx:id="lblInvalidlName" alignment="CENTER" contentDisplay="CENTER" layoutX="251.0" layoutY="146.0" prefHeight="17.0" prefWidth="120.0" style="-fx-background-color: black; -fx-border-color: black;" text="Invalid Last Name" textAlignment="CENTER" textFill="#d72323" textOverrun="CENTER_ELLIPSIS" visible="false">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<effect>
<Bloom threshold="0.22" />
</effect>
<cursor>
<Cursor fx:constant="DISAPPEAR" />
</cursor>
</Label>
<Label id="lblInvalidEmail" fx:id="lblInvalidEmail" alignment="CENTER" contentDisplay="CENTER" layoutX="251.0" layoutY="188.0" prefHeight="17.0" prefWidth="120.0" style="-fx-background-color: black; -fx-border-color: black;" text="Invalid Email" textAlignment="CENTER" textFill="#d72323" textOverrun="CENTER_ELLIPSIS" visible="false">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<effect>
<Bloom threshold="0.22" />
</effect>
<cursor>
<Cursor fx:constant="DISAPPEAR" />
</cursor>
</Label>
<Label id="lblInvalidAddress" fx:id="lblInvalidAddress" alignment="CENTER" contentDisplay="CENTER" layoutX="251.0" layoutY="236.0" prefHeight="17.0" prefWidth="120.0" style="-fx-background-color: black; -fx-border-color: black;" text="Invalid Address" textAlignment="CENTER" textFill="#d72323" textOverrun="CENTER_ELLIPSIS" visible="false">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<effect>
<Bloom threshold="0.22" />
</effect>
<cursor>
<Cursor fx:constant="DISAPPEAR" />
</cursor>
</Label>
<Label id="lblInvalidUsername" fx:id="lblInvalidUsername" alignment="CENTER" contentDisplay="CENTER" layoutX="251.0" layoutY="14.0" prefHeight="17.0" prefWidth="120.0" style="-fx-background-color: black; -fx-border-color: black;" text="Invalid Username" textAlignment="CENTER" textFill="#d72323" textOverrun="CENTER_ELLIPSIS" visible="false">
<font>
<Font name="Wawati SC Regular" size="13.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<effect>
<Bloom threshold="0.22" />
</effect>
<cursor>
<Cursor fx:constant="DISAPPEAR" />
</cursor>
</Label>
</children>
</Pane>
</center>
<top>
<Pane id="customerSignUpLabel_pane" fx:id="customerSignUpLabel_pane" prefHeight="57.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Label id="customerSignUp_label" fx:id="customerSignUp_label" alignment="CENTER" contentDisplay="CENTER" layoutX="114.0" layoutY="14.0" prefHeight="46.0" prefWidth="341.0" style="-fx-background-color: gray;" text="Customer Sign Up ..." textAlignment="CENTER" textFill="#081057">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font name="Copperplate Bold" size="28.0" />
</font>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
</Label>
</children>
</Pane>
</top>
<effect>
<Bloom threshold="1.0">
<input>
<ColorAdjust />
</input>
</Bloom>
</effect>
</BorderPane>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<effect>
<Blend opacity="0.55" />
</effect>
</AnchorPane>
Looking forward to suggestions.
I solved the issue.
It was because one of my parent pane was referencing some other fxml file node which had same fx:id.
Hope that helps other people facing similar issues.

Resources