I want to parse url after I input something in text dialog and comfirm.
But it will cost time, so I created a thread to do it:
public void onAddMod(ActionEvent actionEvent) throws IOException {
Platform.runLater(() -> {
status.setText("Downloading...");
TextInputDialog dialog = new TextInputDialog("fabric-api");
dialog.setTitle("Add a mod from Modrinth");
dialog.setHeaderText("");
dialog.setContentText("Modrinth slug: ");
Optional<String> opt = dialog.showAndWait();
if (opt.isPresent()) {
try {
// parsing
Information info = ModrinthUtils.information(opt.get());
DataSaver.MODS.put(info.modName(), info);
ModList.getItems().add(info.modName());
} catch (IOException ignored) {}
}
status.setText("Finished!");
});
}
*onAddMod() will run after the button pressed
However, Platform.runLater() CANNOT let the thread "run later". When I confirm, the program stopped until parsing finished.
How can I fix it? Where am I doing wrong?