Hi,
I start a new Thread and in it I change some UI elements:
final Label label = new Label();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// do work
label.setText("text");
}
});
thread.start();
The strange thing is, that on my machine the above code works, and on another machine it doesn't ("not on FX application thread").
I know that I could just wrap label.setText() with Platform.runLater(). But actually I want to know, why this code works at all on my machine?
Another scenario is when I don't access UI elements directly but use e.g. binding to update them. E.g. I update a StringProperty in my Thread, which is bound to a textproperty of a Label. Do I need to use runLater then too?
Is there a rule of thumb, when to wrap in Platform.runLater? Do I just have to know, when something triggers an UI update? But still, why does the above code at all (at least on my machine)?
Edit: I think on the other machine is JFX 2.0.2 (it was the JFX, which is bundled with Java JDK 7 Update 2), and on mine is 2.0.1.
Edited by: csh on 15.12.2011 01:18