主要类jfx没有显示任何内容

时间:2016-06-13 12:36:57

标签: javafx

你好我在javaFx中非常棒,我有这个主要的类, 当我从日食开始,它没有显示任何东西, 我在日志查看器中没有错误,我在选择MainApp类之后从run-> runAs-> java应用程序中进行了测试。

public class MainApp extends Application {

    private Stage primaryStage;
    private BorderPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("AddressApp");

        initRootLayout();

        showPersonOverview();
    }

    /**
     * returns the main stage.
     * @return
     */
    public Stage getPrimaryStage(){
        return primaryStage;
    }

    /**
     * 
     * Initializes the root layout
     */
    public void initRootLayout() {
        // Load root layout from fxml file.
        try {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Show the person overview insiede the root layout
     */
    public void showPersonOverview() {
        try{
            //Load person overview
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/PersonOverview.fxml"));
            AnchorPane personOverview = (AnchorPane) loader.load();

            // Set person overview into the center of root layout
            rootLayout.setCenter(personOverview);
        }
        catch (IOException e){
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        launch(args);
    }
}

0 个答案:

没有答案