How to change the Label text and update the window?
#!/usr/bin/env fan
using fwt
class ChangeLabelText
{
Label l := Label { text = "hello world" }
Window w := Window { l }
Void main() {
w.open
// Now I want to change the Label text, but this doesn't work:
l.text = "foobar"
w.repaint
}
}
Using Text instead of Label didn't work either. Any help please?
andySun 15 Mar 2009
Its actually working - but w.open is blocking the main thread - so that code doesn't get executed till after you close the window. If you modify the label on the event thread, it should work - as in the example code below:
using fwt
class ChangeLabelText
{
Label l := Label { text = "hello world" }
Button b := Button
{
text = "Click me!"
onAction.add |,| { l.text = "foobar" }
}
Window w := Window
{
l
b
}
Void main() { w.open }
}
Dubhead Sun 15 Mar 2009
How to change the Label text and update the window?
#!/usr/bin/env fan using fwt class ChangeLabelText { Label l := Label { text = "hello world" } Window w := Window { l } Void main() { w.open // Now I want to change the Label text, but this doesn't work: l.text = "foobar" w.repaint } }Using Text instead of Label didn't work either. Any help please?
andy Sun 15 Mar 2009
Its actually working - but
w.openis blocking the main thread - so that code doesn't get executed till after you close the window. If you modify the label on the event thread, it should work - as in the example code below:using fwt class ChangeLabelText { Label l := Label { text = "hello world" } Button b := Button { text = "Click me!" onAction.add |,| { l.text = "foobar" } } Window w := Window { l b } Void main() { w.open } }Dubhead Mon 16 Mar 2009
Ah, I see. It worked, thank you!