0

I am trying to load a fxml file in borderPane.

and the borderPane is inside a fxml controller (it's like loading a fxml in fxml) but I am getting a white screen

this is the code :

package gui;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.net.URL;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.stage.Stage;

public class CompanyMainC extends Application
{
    private Stage primaryStage;
    private AnchorPane mainLayout;
    @FXML
    private AnchorPane mainProgramPane;
    @FXML
    private Label headlineLable;
    @FXML
    private BorderPane whiteBorderPane;
    private URL path;
    @FXML
    void handleHomeButtonClick(ActionEvent event) 
    {
        FxmlLoader object = new FxmlLoader();
        Pane view = object.getPage("CompanyHome");
        whiteBorderPane.setCenter(view);
    }

    @FXML
    void handleHomeHeatingButtonClick(ActionEvent event)
    {
        FxmlLoader object = new FxmlLoader();
        Pane view = object.getPage("CompanyHomeHeatingMain");
        whiteBorderPane.setCenter(view);
    }

    @FXML
    void handleMessagesButtonClick(ActionEvent event)
    {
        FxmlLoader object = new FxmlLoader();
        Pane view = object.getPage("CompanyMessagesMain");
        whiteBorderPane.setCenter(view);
    }

    @Override
    public void start(Stage primaryStage) throws IOException
    {   this.primaryStage = primaryStage;
        this.primaryStage.setTitle("MyFuel App");

        initializeView();
    }

    private void initializeView() throws IOException
    {
        // load everything we are doing in the scene builder
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(ClientMainC.class.getResource("/gui/CompanyMainView.fxml"));
        mainLayout = loader.load();

        Scene scene = new Scene(mainLayout);

        primaryStage.setScene(scene);

        primaryStage.show();
        FXMLLoader loader2 = new FXMLLoader();
        path = getClass().getResource("CompanyHome.fxml");
        try {
        loader2.setLocation(path);            

        whiteBorderPane=new BorderPane();
        whiteBorderPane.setCenter(loader2.load());
        } catch (IOException e){
            System.out.println("Not found: " + path);
            e.printStackTrace();
        }     
    }

    public static void main(String[] args)
    {

        launch(args);
    }
}

I am getting a white screen inside the companyMainView but I want to see the CompanyHome inside the CompanyMainView after running the project .(without pressing any button)

Thank you for helping

  • https://stackoverflow.com/questions/32081713/javafx-controller-class-not-working – James_D May 27 '20 at 12:53
  • 2
    You need to start with 1. An `Application` subclass, which is not the same as the class used for any controllers, and 2. A separate controller class for each FXML file. Use the `initialize()` method in the controllers to perform initialization work for each one (e.g. loading the CompanyHome.fxml into the center of the border pane). – James_D May 27 '20 at 14:37

0 Answers0