Executable Jar limited to one window with JavaFX

白昼怎懂夜的黑 提交于 2019-12-22 12:17:29

问题


I am building a JavaFX application through E(fx)clipse and Java Scene Builder.

The basic functionality is a login window. Once logged in, new window opens and the login window disapears. Right now it's just at the prototype stage.

When running out of ecplise, the functionality I want is all there. Login window shows up on start (code looking as such)

@Override
public void start(Stage primaryStage) {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("view/login.fxml"), ResourceBundle.getBundle("ca.sportstats.resources.labels"));

        primaryStage.setTitle("SportStats Live Update Tool : Login");
        primaryStage.setScene(new Scene(root, 450, 300));
        primaryStage.show();
    } catch (IOException e) {
        //Change this to open a small popup window.
        System.out.println("Could not deploy");
    }
}

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

There is one button on this window that simply opens another (the login logic will come later and not an issue here).

    btnLogin.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {

            //TODO: Login logic.
            //On success allow to open the tool (aka main window);

            Parent root;
            try {
                root = FXMLLoader.load(getClass().getResource("../view/selector.fxml"), resources);
                Stage stage = new Stage();
                stage.setTitle("Selector");
                stage.setScene(new Scene(root, 450, 450));
                stage.show();

                //hide this current window
                ((Node)(event.getSource())).getScene().getWindow().hide();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

This works no problem in Ecplise. BUT! When I build this (in the fashion described on the e(fx)clipse tutorials I get an executable jar, but only get the login window. When I click my button the 2nd window doesn't show up.


回答1:


The problem I think is that in jars you can't do relative paths. Inside Eclipse you are running on the filesystem where this is not a problem



来源:https://stackoverflow.com/questions/14241283/executable-jar-limited-to-one-window-with-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!