Extract contents from Scene

I am trying to extract the contents from a scene and put in a pane. The problem is that nothing appears in the pane if I get the root component from the scene and add it to the pane.

Note: the scene is not added to a stage or to any other component.

The following is my (messy, for now) code:

public class JanelaPrincipalController extends Controller implements Initializable {

@FXML
private ResourceBundle resources;

@FXML
private URL location;

@FXML
private StackPane conteudo;

@FXML
private MenuItem miBolsas;

@FXML
private MenuItem miCorretoras;

/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    miBolsas.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            System.out.println("Action performed");
            conteudo.getChildren().clear();
            SceneData sceneData = MainClass.getInstance().getScene(SceneType.LISTA_BOLSAS);
            Parent root = sceneData.scene().getRoot();
            conteudo.getChildren().add(root);
            //conteudo.getChildren().add(new Label("Teste"));
        }
    });
}

@Override
public void open() {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void process(Action action) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void close() {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}

Answers


The same Node (in this case the Parent), con not be shown twise, therefore, if your scene was being shown, you will need to remove the root from the scene, and then you add it to stackpane.


The problem was the scene. The root node was added to a Scene, so it can't be displayed in other place. Have to remove the node from the Scene.

I am refactoring the code, I just don't need to add some contents directly to scenes now.

I was using this method in my MainClass:

public static SceneData loadSceneFromFXML(final String fxmlFile, final Controller controller) throws IOException {
    FXMLLoader fxmlLoader = new FXMLLoader(MainClass.class.getResource(fxmlFile));
    if (controller != null) {
        fxmlLoader.setController(controller);
    }
    Parent root = (Parent) fxmlLoader.load();
    Scene scene = new Scene(root);
    scene.getStylesheets().add(CSS);
    return new SceneData(scene, controller);
}

Need Your Help

Finding the Average of a Column in VBA

excel vba overflow average

I am attempting to find the average for all of the numbers in a given column.

MongoDB: Determining which Secondary is being read from

java mongodb database

Hey first time using mongo replica sets, and I've configured a set of 3 servers in Java. I'm trying to determine which secondary is being read from by my service (using secondary preferred). Does the