I need to load from a button in a menu that is a FXML file loaded according to the user that authenticates another scene to a panel of the scene that contains this menu as I do?
in this way I charge the menu
Principal.fxml from Your controller
private void loadSession () {
Parent root = null;
String menu = "";
try {
// elige el menu segun el rol admin o estandard
if(cuentaactiva.getUser_root()==0){
menu = "/pVistas/includes/MenuAdmin";
}else{
menu = "/pVistas/includes/MenuDefault";
}
//nombre de la Cuenta autenticada
Lbl_user.setText(cuentaactiva.getUser_name());
//cargar el menu
root = FXMLLoader.load(getClass().getResource(menu+".fxml"));
} catch (IOException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
// pone el menu en su lugar
if(!ContentMenu.getChildren().isEmpty())
{
ContentMenu.getChildren().remove(0);
ContentMenu.getChildren().add(root);
}else{
ContentMenu.getChildren().add(root);}
}
the admin menu has 4 buttons, for example, and I need that when the accounts button loads me in the same parent but in another container that is a Pane the corresponding FXML.
for this I have done this, a function that loads me and can call it from that button but nothing comes out or gives null pointer error
Principal.FXML from your controller @FXML public void loadfunctions (String url) {
Pane root = new Pane();
try {
root = FXMLLoader.load(getClass().getResource(url+".fxml"));
Contentpane.getChildren().clear();
Contentpane.getChildren().add(root);
} catch (IOException ex) {
Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
}
}
This is what I call from the menuAdmin.FXML from your controller
@FXML
private void OpnCuentas(ActionEvent event) throws IOException {
String url = "/pVistas/Subinterfaces/Cuentas";
PrincipalController PpalController = new PrincipalController();
PpalController.cargarfunciones(url);
}
Waiting for help. greetings