问题描述
我正在通过 E(fx)clipse 和 Java Scene Builder 构建JavaFX应用程序.
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.
当ecplise用尽时,我想要的功能就在那里.登录窗口在启动时显示(代码看起来像这样)
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();
}
}
});
这在Ecplise中没有问题.但!当我以e(fx)剪辑教程中的所述的方式构建时,我得到了一个可执行的jar,但只有登录窗口.单击我的按钮时, 2nd 窗口不会显示.
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.
推荐答案
我认为的问题是,在jar中,您无法执行相对路径.在Eclipse内部,您正在没有问题的文件系统上运行
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
这篇关于可执行Jar限于JavaFX的一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!