Abrir tela travando a tela original

4 respostas Resolvido
java
Krismorte

Galera to começando em JavaFX e estou me adaptando bem, porém ainda não consegui descobrir como simular a função que o JDialog do swinfg fazia travando a tela que chamou até que o Dialog fosse concluido.

Alguém poderia me apontar o caminho.

4 Respostas

gbrvalerio

ao invés de .show() chama o .showAndWait() ^^

Krismorte

Não rolou, então vou explicar melhor como estou fazendo.

Criei uma classe abstrata para que minhas telas FX herdem alguns metodos.

public abstract class fXTelas {

    public abstract void showScreen();

    public void initLayout(String title, Node node, String fxmlPath) {
        try {
            // Carrega o root layout do arquivo fxml.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass()
                    .getResource(fxmlPath));
            if (node instanceof BorderPane) {
                BorderPane rootLayout = (BorderPane) loader.load();
                showLayout(title, rootLayout);
            } else if (node instanceof AnchorPane) {
                AnchorPane rootLayout = (AnchorPane) loader.load();
                showLayout(title, rootLayout);
            }

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

    private void showLayout(String title, Parent node) {
        Stage primaryStage = new Stage();
        Scene scene = new Scene(node);
        primaryStage.setTitle(title);
        primaryStage.getIcons().add(new Image("file:images/icone.png"));
        primaryStage.setScene(scene);

        primaryStage.show();
    }

    public void initLayoutDialog(String title, Node node, String fxmlPath) {
        try {
            // Carrega o root layout do arquivo fxml.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass()
                    .getResource(fxmlPath));
            if (node instanceof BorderPane) {
                BorderPane rootLayout = (BorderPane) loader.load();
                showLayoutDialog(title, rootLayout);
            } else if (node instanceof AnchorPane) {
                AnchorPane rootLayout = (AnchorPane) loader.load();
                showLayoutDialog(title, rootLayout);
            }

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

    private void showLayoutDialog(String title, Parent node) {
        Stage primaryStage = new Stage();
        Scene scene = new Scene(node);
        primaryStage.setTitle(title);
        primaryStage.getIcons().add(new Image("file:images/icone.png"));
        primaryStage.setScene(scene);

        primaryStage.showAndWait();
    }

}

As demais telas herdam dessa e implementam o metodo

public abstract void showScreen();

Criei um novo metodo para o comportamento .showAndWait(), porem o mesmo não funcionou

OBS: as telas abrem normalmente sem erro.

gbrvalerio
Solucao aceita
primaryStage.initModality(Modality.APPLICATION_MODAL);

coloca antes do .showAndWait()

acho que é isso ou então é com Modality.WINDOW_MODAL
Krismorte

Show!!!

Criado 16 de fevereiro de 2016
Ultima resposta 16 de fev. de 2016
Respostas 4
Participantes 2