【发布时间】:2019-12-29 20:10:00
【问题描述】:
我正在尝试通过JavaFX 创建自定义弹出窗口,但从static 方法启动它时遇到了一些问题。
如何通过static 方法启动新窗口?
关于我的程序的一般信息 - 用户应键入数据并选择/取消选择 checkbox。按下“提交”button 运行一个 static 方法来做一些事情,并根据用户 checkbox 选择 - 运行另一个做其他事情的方法。
如果取消选择checkbox,我想打开另一个窗口(自定义弹出窗口)。
但是,我不能这样做,因为我所有的方法都是static(无法更改)。方法uploadCustomIndexWindow 被定义为静态,因此,当我尝试启动自定义弹出窗口时,我收到错误
无法对非静态方法 getClass() 进行静态引用 来自 Object 类型。
.
private static Index getStartEndIndex(String childFormat, boolean isFromExportTDP) {
if(IndexMap.getIndexMap().get(childFormat) == null) {
Index index;
if (isFromExportTDP) {
if(childFormat.equalsIgnoreCase("pdf")){
index = new Index(childFormat, 2, 12);
}
else {
index = new Index(childFormat, 2, 5);
}
}
else{
// Custom pop-up
uploadCustomIndexWindow();
index = new Index(childFormat, startIndex, endIndex);
}
IndexMap.getIndexMap().put(childFormat, index);
}
return IndexMap.getIndexMap().get(childFormat);
}
public static void uploadCustomIndexWindow() throws IOException{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CustomIndexScreen.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.setTitle("Custom Index Screen");
stage.show();
}
【问题讨论】: