0
I need to execute a method within a Thread that contains Alert and Dialog. As you already know Javafx has the limitation of not being able to show Alert or Dialog inside a Thread, so I put them inside a Platform.runLater and it works, the problem is that while Alert is displayed Thread follows its flow. I would like the behavior to be the same when not using Thread, causing the flow to be paused while Alert is not closed. Would you be so kind as to help me ? Below excerpt from the sample code:
// Processa conteudo dentro da Task
public static void testeThread()
{
Runnable task = new Runnable()
{
public void run()
{
System.out.println("inciando Thread, executa tarefas ");
// *** Tratamento para alert/Dialog
Platform.runLater(()->
{
//Exibe mensagem ao usuario sobre bloqueio
Alert alertLicencaInvalida = new Alert(Alert.AlertType.ERROR);
alertLicencaInvalida.setTitle("Erro");
alertLicencaInvalida.setHeaderText("Erro");
alertLicencaInvalida.setContentText(" Ocorreu ");
alertLicencaInvalida.showAndWait();
// enquanto estiver aqui dentro, Thread deve ficar aguardando
});
// continuar Thread apos Alert for fechado
System.out.println("Continuando Thread ");
}
};
// Run the task in a background thread
Thread backgroundThread = new Thread(task);
// Terminate the running thread if the application exits
backgroundThread.setDaemon(true);
// Start the thread
backgroundThread.start();
}
Thank you @Piovezan your explanation has helped me a lot. I had already found the code you mentioned in the reply, but had failed to apply in my project.
– Douglas Ribeiro