load several scenes from scenes already loaded in a scene

0

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

    
asked by Ariel 29.10.2018 в 15:07
source

1 answer

0

These methods can help you in what you want to do. My first suggestion is always to undo the code so that you do not have everything together but you can always reuse the algorithms.

public Parent cargarFXML(String rutaFXML) {
    // ejemplo para escribir la ruta del FXML
    // /stdxml/vista/auxiliares/Modelo1.fxml

    Parent root = null;

    try {

       root = FXMLLoader.load(getClass().getResource(rutaFXML));

    } catch (IOException ex) {
        Logger.getLogger(VentanaImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    return root;
}

the following is to convert the window to modal

private Stage ventanaModal(Parent root){
    final Stage ventana = new Stage(StageStyle.TRANSPARENT);

    Scene scene = new Scene(root);
    scene.setFill(null);


    ventana.initModality(Modality.APPLICATION_MODAL);
    ventana.setScene(scene);
    ventana.setResizable(false);
    ventana.sizeToScene();

  return ventana;
}

To close the window

public void cerrarVentana(Node nodo){
   Stage stg = (Stage) nodo.getScene().getWindow();
   stg.close();
}

Here would be a method to load a window. For simplicity, only the necessary was placed. You can modify it and show any desired scene

public void mensajeria(String titulo, String contenido) {
   Parent root = this.cargarFXML("/stdxml/vista/emergentes/Mensaje.fxml");


    Platform.runLater(new Runnable() {
       @Override
       public void run() {
            new VentanaImpl().ventanaModal(root).showAndWait();
       }
   });


}
    
answered by 26.11.2018 в 01:35