JavaFX Windows在视觉上无响应

时间:2018-07-10 15:07:46

标签: java user-interface javafx

我将JavaFX用于系统的UI,加载不同的窗口时遇到问题。由于某种原因,窗口已加载但没有视觉响应。

例如,我可以按下窗口上的一个按钮,他将从功能角度进行响应,但在视觉上他不会做出反应。

我认为问题是由此类引起的:

public class ViewLogic {
protected static final Rectangle2D FULL_SCREEN = Screen.getPrimary().getBounds();
protected static final Rectangle2D VISIBLE_SCREEN = Screen.getPrimary().getVisualBounds();

protected static SysData sysData;
protected static String currentUserID;
protected static E_UserType currentUserType;

public static void initUI() throws MalformedURLException {
    sysData = SysData.getInstance();

    newStadiumCreationWindow();
}

protected static void newWindow(URL fxmlLocation, Stage stage, Double prefWidth,
        Double prefHeight, Double minWidth, Double minHeight, Double maxWidth,
        Double maxHeight, boolean resizable, String title, boolean waitFor) {
    try {
        FXMLLoader loader = new FXMLLoader(fxmlLocation);
        Parent root = loader.load();
        Scene scene;

        if (prefWidth == null || prefHeight == null)
            scene = new Scene(root);
        else
            scene = new Scene(root, prefWidth, prefHeight);

        stage.setScene(scene);

        if (minWidth != null)
            stage.setMinWidth(minWidth);
        if (minHeight != null)
            stage.setMinHeight(minHeight);
        if (maxWidth != null)
            stage.setMaxWidth(maxWidth);
        if (maxHeight != null)
            stage.setMaxHeight(maxHeight);

        stage.setResizable(resizable);

        if (title != null && !title.isEmpty() && !title.trim().isEmpty())
            stage.setTitle(title);

        if (waitFor)
            stage.initModality(Modality.APPLICATION_MODAL);

        stage.showAndWait();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}



protected static void newStadiumCreationWindow() {
    Stage stage = new Stage();
    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            stage.close();
            ViewLogic.newAdminStadiumWindow();
        }
    });

    newWindow(ViewLogic.class.getResource("StadiumAdminCreation.fxml"),
            stage,
            null,null, null, null, null, null,
            true,
            "Stadium Settings",
            false);
}


private static void saveOnExit() {

    Alert alert = new Alert(AlertType.WARNING);

    ButtonType buttonTypeYes;
    ButtonType buttonTypeNo;
    if (AbstractController.language.equalsIgnoreCase(LangEnglish.langName)) {
        buttonTypeYes = new ButtonType(LangEnglish.yes, ButtonData.YES);
        buttonTypeNo = new  ButtonType(LangEnglish.no, ButtonData.NO);

        alert.setHeaderText(LangEnglish.saveChanges);
        alert.setContentText("");
    }
    else {
        buttonTypeYes = new ButtonType(LangHebrew.yes, ButtonData.YES);
        buttonTypeNo = new ButtonType(LangHebrew.no, ButtonData.NO);
        alert.setHeaderText(LangHebrew.saveChanges);
        alert.setContentText("");
    }
    alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo);

    alert.setTitle("Save Changes");

    Optional<ButtonType> answer = alert.showAndWait();

    //ButtonType answer = alert.getResult();

    if (answer.get().getButtonData() == ButtonData.YES ) {
        //Serialize
        System.out.println("Serialized");

    }

}
}

0 个答案:

没有答案