I'm trying to create custom-popup via JavaFX
, and have some trouble with initiating it from a static
method.
How can I initiate a new window from a static
method?
General information about my program - The user should type data and select/deselect a checkbox
. Pressing on "submit" button
runs a static
method that does some stuff, and according to the user checkbox
selection - run another method that does other stuff.
If the checkbox
is deselected, I would like to open another window (custom popup).
However, I can't do that, since all my methods are static
(can't change that). The method uploadCustomIndexWindow
is defined as static, and therefore, when I try to initiate my custom-popup, I get the error
Cannot make a static reference to the non-static method getClass() from the type 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();
}