我正在通过 E(fx)clipse 和 Java Scene Builder 构建JavaFX应用程序。
基本功能是登录窗口。登录后,将打开新窗口,登录窗口将消失。现在它只是在原型阶段。
当用完ecplise时,我想要的功能就在那里。登录窗口显示在启动时(代码看起来如此)
@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);
}
此窗口上只有一个按钮可以打开另一个按钮(登录逻辑稍后会出现,而不是问题)。
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();
}
}
});
这在Ecplise中没有问题。但!当我构建它时(以on the e(fx)clipse tutorials描述的方式,我得到一个可执行jar,但只获取登录窗口。当我点击我的按钮时, 2nd 窗口不显示。
答案 0 :(得分:4)
我认为问题是在罐子里你不能做相对路径。在Eclipse内部,您运行的文件系统不是问题