The task is to click on a specific program button (JavaFX GUI) to start a wait gif that will spin while the main code is filled. For this there is a separate method - showGif (), and its call through Platform.runLater as a separate stream (it starts when you click on the button).
The problem is that the gif still runs only after all the program code has been executed - i.e. not a separate thread at the beginning of the program, as I wanted.
In similar questions for people, everything works through Platform.runLater - what am I doing wrong?
Button action:
btn_find.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { // ΠΎΡΠΏΡΠ°Π²Π»ΡΠ΅Ρ Π²Π²Π΅Π΄Π΅Π½Π½ΡΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Π΅ΠΌ ΡΡΡΠ»ΠΊΡ Π² ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΡ, ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ Π³ΠΈΡΠΊΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ new Thread(new Runnable() { public void run() { Platform.runLater(new Runnable() { public void run() { showGif(); } }); } }).start(); ShowGif () method:
private void showGif() { System.out.println("Π·Π°ΠΏΡΡΠΊΠ°Ρ Π³ΠΈΡΠΊΡ"); File file = new File("/Users/user/Desktop/cat-preloader.gif"); String localUrl = null; try { localUrl = file.toURI().toURL().toString(); } catch (MalformedURLException e) { e.printStackTrace(); } Image image = new Image(localUrl, 200,200, false, true); ImageView imageView = new ImageView(image); hb = new HBox(); hb.setStyle("-fx-background-color: lightgrey"); hb.setOpacity(0.7); hb.getChildren().add(imageView); HBox.setMargin(imageView, new Insets(300, 100, 60, 200)); BorderPane.setMargin(hb, new Insets(0, 0,600, 0)); MainView.pane.setCenter(hb); // Π·Π΄Π΅ΡΡ Π·Π°ΠΌΠΈΠ½ΠΊΠ° - Π³ΠΈΡ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ°Π΅ΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΠΎΡΠ»Π΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ Π²ΡΠ΅ΠΉ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ System.out.println("Π³ΠΈΡΠΊΠ° Π·Π°ΠΏΡΡΠ΅Π½Π°"); }
new Task<>()and the gif can also be run in the same way. - Tsyklop 8:19 pm