Update JavaFX in JFXPanel while EDT is blocked
Artem Ananiev
artem.ananiev at oracle.com
Mon Jun 18 05:49:47 PDT 2012
Hi, Werner,
your scenario doesn't look JFXPanel specific: you block EDT and at the
same time request Swing to repaint. As expected, it doesn't work, as
Swing repaints on EDT :) paintImmediately() may sometimes help, but be
very careful: if you call Platform.runLatter() to update FX progress bar
and then right after that call JFXPanel.paintImmediately(), you will
likely get the old state of the progress bar.
Ideally, you should move all the initialization code to background
thread(s). When you need to update UI, e.g. update progress bar value,
you need:
1. In pure Swing app: call invokeLater() and set JProgressBar's value
from the Runnable. JProgressBar will then implicitly call repaint().
Some time later the progress bar will be painted by RepaintManager.
2. in FX/Swing app: call runLater() and set ProgressBar's value from the
Runnable. ProgressBar will then invalidate FX scene, which will trigger
FX repaint, which will automatically call JFXPanel.repaint().
Thanks,
Artem
On 6/15/2012 11:32 PM, Werner Lehmann wrote:
> Hi,
>
> is there a way to force a JFXPanel to update itself while the EDT is
> blocked?
>
> This is my situation: on startup the Swing application shows a login
> screen with a progress bar. This login screen is a JFXPanel and the
> progress bar is a JavaFX control. In the background lots of
> initializations are going on, and much of this should run on the EDT.
> Therefore it is executing within SwingUtilties.invokeAndWait - but that
> also seems to block updates to the JFXPanel and the progressbar is not
> updated.
>
> Maybe I can force an immediate repaint of the progressbar only? After
> all, I am running two GUI toolkits at the same time, both with their own
> GUI threads, so I'd like to take advantage of that...
>
> Thx.
>
> Werner
More information about the openjfx-dev
mailing list