首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >maven构建后某些场景未加载

maven构建后某些场景未加载
EN

Stack Overflow用户
提问于 2015-05-10 03:57:20
回答 1查看 343关注 0票数 18

我正在netbeans中开发JavaFx应用程序,在netbeans中项目正在构建并运行良好。

我从我的项目做了一个构建(mvn package),它没有错误地完成了,但当我启动程序时,它并没有加载所有的场景,在这种情况下,FXMLLoader返回空值。

同一文件夹中的所有.fxml文件。

代码语言:javascript
复制
public class JavaFXApplication extends Application {

    public static final String TOOLBAR_MAIN = "toolbarMain";
    public static final String TOOLBAR_MAIN_FXML = "/fxml/ToolbarMain.fxml";
    public static final String TOOLBAR_SUB = "toolbarSub";
    public static final String TOOLBAR_SUB_FXML = "/fxml/ToolbarSub.fxml";

    public static final String NEW_SESSION_PANEL = "newSession";
    public static final String NEW_SESSION_PANEL_FXML = "/fxml/NewSessionPanel.fxml";
    public static final String OPEN_SESSION_PANEL = "openSession";
    public static final String OPEN_SESSION_PANEL_FXML = "/fxml/OpenSessionPanel.fxml";
    public static final String CONNECTIONS_PANEL = "connections";
    public static final String CONNECTIONS_PANEL_FXML = "/fxml/ConnectionsPanel.fxml";
    public static final String LOGS_PANEL = "logs";
    public static final String LOGS_PANEL_FXML = "/fxml/LogsPanel.fxml";
    public static final String EXCEPTIONS_PANEL = "exceptions";
    public static final String EXCEPTIONS_PANEL_FXML = "/fxml/ExceptionsPanel.fxml";
    public static final String MESSAGES_PANEL = "messages";
    public static final String MESSAGES_PANEL_FXML = "/fxml/MessagesPanel.fxml";

    public static ScreensController menuContainer = new ScreensController();
    public static ScreensController contentContainer = new ScreensController();

    public static ServerService server = new ServerService();

    public static Stage STAGE;

    @Override
    public void start(Stage primaryStage) throws Exception {

        STAGE = primaryStage;

        primaryStage.setOnCloseRequest((WindowEvent t) -> {
            if (server.isRunning()) {
                server.cancel();
            }
        });

        menuContainer.loadScreen(JavaFXApplication.TOOLBAR_MAIN,
                JavaFXApplication.TOOLBAR_MAIN_FXML);
        menuContainer.loadScreen(JavaFXApplication.TOOLBAR_SUB,
                JavaFXApplication.TOOLBAR_SUB_FXML);

        contentContainer.loadScreen(JavaFXApplication.NEW_SESSION_PANEL,
                JavaFXApplication.NEW_SESSION_PANEL_FXML);
        contentContainer.loadScreen(JavaFXApplication.OPEN_SESSION_PANEL,
                JavaFXApplication.OPEN_SESSION_PANEL_FXML);
        contentContainer.loadScreen(JavaFXApplication.NEW_SESSION_PANEL,
                JavaFXApplication.NEW_SESSION_PANEL_FXML);
        contentContainer.loadScreen(JavaFXApplication.CONNECTIONS_PANEL,
                JavaFXApplication.CONNECTIONS_PANEL_FXML);
        contentContainer.loadScreen(JavaFXApplication.LOGS_PANEL,
                JavaFXApplication.LOGS_PANEL_FXML);
        contentContainer.loadScreen(JavaFXApplication.EXCEPTIONS_PANEL,
                JavaFXApplication.EXCEPTIONS_PANEL_FXML);
        contentContainer.loadScreen(JavaFXApplication.MESSAGES_PANEL,
                JavaFXApplication.MESSAGES_PANEL_FXML);
        menuContainer.setScreen(JavaFXApplication.TOOLBAR_MAIN);
        contentContainer.setScreen(JavaFXApplication.NEW_SESSION_PANEL);

        SplitPane root = new SplitPane();

        root.getItems().addAll(menuContainer, contentContainer);
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.setResizable(false);
        primaryStage.setTitle("Exam Supervisor");

    }

屏幕控制器加载屏幕的位置:

代码语言:javascript
复制
public class ScreensController extends StackPane {

    private HashMap<String, Node> screens = new HashMap<>();

    public void addScreen(String name, Node screen) {
        screens.put(name, screen);
    }

    public boolean loadScreen(String name, String resource) {
        try {
            FXMLLoader myLoader = new FXMLLoader(getClass().getResource(resource));
            System.out.println("name:" + name + " ,resource" + resource + " ,loader:" + myLoader.getLocation());
            Parent loadScreen = myLoader.load();
            ControlledScreen myScreenControler
                    = myLoader.getController();
            myScreenControler.setScreenParent(this);
            addScreen(name, loadScreen);
            return true;
        } catch (Exception e) {
            System.out.println("name: " + name + ", resource" + resource + " ,exception: " + e.getMessage());
            return false;
        }
    }

    public boolean setScreen(final String name) {

        if (screens.get(name) != null) {
            final DoubleProperty opacity = opacityProperty();

            if (!getChildren().isEmpty()) {
                getChildren().remove(0);
                getChildren().add(0, screens.get(name));
            } else {
                getChildren().add(screens.get(name));
            }
            return true;
        } else {
            System.out.println(screens.get(name) + " ,screen hasn't been loaded!\n");
            return false;
        }

    }

    public boolean unloadScreen(String name) {
        if (screens.remove(name) == null) {
            System.out.println("Screen didn't exist");
            return false;
        } else {
            return true;
        }
    }
}

我的github资源库:https://github.com/eszikk/ExamSuperVisorServer

EN

回答 1

Stack Overflow用户

发布于 2015-05-20 07:11:33

试着使用javafx-maven-plugin Hope,它可以帮助你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30144403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档