I have a problem which I'm struggling with for the past few days and deadline for the project is coming. I'mamking a JavaFX desktop app and I encountered an issue: I created GUI with SceneBuilder and my menu is supposed to be dynamic (get items from the database and throw into the menu). I tried to do it and the issue is when I run the app menu doesn't change. What I'm doing wrong?
Main.java
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("home.fxml"));
primaryStage.setTitle("Whatever");
MainController.setMenu();
primaryStage.setScene(new Scene(root, 1200, 800));
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
primaryStage.setX(primaryScreenBounds.getMinX());
primaryStage.setY(primaryScreenBounds.getMinY());
primaryStage.setWidth(primaryScreenBounds.getWidth());
primaryStage.setHeight(primaryScreenBounds.getHeight());
primaryStage.show();
}
public static void main(String[] args) throws ClassNotFoundException, SQLException {
launch(args);
}
MainController.java
public static void setMenu() throws SQLException, ClassNotFoundException {
myMenu = new Menu();
String myQuery = "SELECT name FROM USER.TABLE1";
Connection connection = DBConnect.connect();
Statement statement = connection.createStatement();
ResultSet data = statement.executeQuery(myQuery);
while (data.next()) {
System.out.println(data.getString(1));//works
String dataString = data.getString(1);
myMenu.getItems().add(new MenuItem(dataString));
}
}