Bonjour à tous,
J’ai un souci. Je veux que mon Thread change la visibilité de ma ProgressBar.
Mais ça me renvoie :
Voici mon code que j'ai raccourci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 Exception in thread "Thread-4" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-4 at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source) at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source) at javafx.scene.Scene.addToDirtyList(Unknown Source) at javafx.scene.Node.addToSceneDirtyList(Unknown Source) at javafx.scene.Node.impl_markDirty(Unknown Source) at javafx.scene.Node$5.invalidated(Unknown Source) at javafx.beans.property.BooleanPropertyBase.markInvalid(Unknown Source) at javafx.beans.property.BooleanPropertyBase.set(Unknown Source) at javafx.css.StyleableBooleanProperty.set(Unknown Source) at javafx.scene.Node.setVisible(Unknown Source) at application.ThreadImag.run(ThreadImag.java:27)
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package application; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.ProgressBar; import javafx.stage.Stage; public class ProgressBarApp extends Application { public static ProgressBar p1; public Parent createContent() { p1 = new ProgressBar(); ThreadImag t= new ThreadImag(); t.start(); Group group = new Group(); group.getChildren().addAll(p1); return group; } @Override public void start(Stage primaryStage) throws Exception { primaryStage.setScene(new Scene(createContent())); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package application; public class ThreadImag extends Thread{ private int nb_ligne=1200; int ii=0; public ThreadImag() { } public void run() { for (int i = 0; i < nb_ligne; i++) { if (i > ii + 99) { ii = i; System.out.print("\r" + i + "/" + nb_ligne); ProgressBarApp.p1.setProgress((double)(i)/nb_ligne); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } ProgressBarApp.p1.setVisible(false); System.out.print("\n"); System.out.println("Thread off"); Thread.currentThread().interrupt(); } }
Sinon j'avais essayé de modifier de texte (pour afficher le pourcentage de ma ProgressBar) et ça me renvoyait la même erreur
J'ai essayé de trouver cette erreur sur Google, mais vue que je ne la comprends pas très bien et que je fais habituellement des Thread en C, j'avoue avoir du mal à trouver.
Merci
David B.
Partager