我正在尝试通过创建自定义弹出窗口JavaFX
,并且从static
方法中启动它时遇到了一些麻烦。
如何从static
方法启动新窗口?
有关我的程序的一般信息-用户应键入data并选择/取消选择一个checkbox
。按下“提交”button
将运行一个static
执行某些工作的方法,并根据用户的checkbox
选择-运行另一种执行其他工作的方法。
如果checkbox
取消选择,我想打开另一个窗口(自定义弹出窗口)。
但是,我无法做到这一点,因为我所有的方法都是static
(无法更改)。该方法uploadCustomIndexWindow
定义为静态,因此,当我尝试启动自定义弹出窗口时,出现错误
无法从对象类型对非静态方法getClass()进行静态引用。
。
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();
}
请使用“ YourClassName.class”而不是“ getClass()”!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句