Hi, Hendrik,

please, try adding the following line to the very beginning of the main() method:

PlatformImpl.startup(() -> {});

PlatformImpl is an internal class from com.sun.javafx.application, so it is not an official way to do the job, it's just a workaround.

Another option is to wrap all the code after JFXPanel.<init>() into additional invokeLater(). By the time when JFXPanel constructor is finished, FX has already set up single threaded event dispatching mechanism, so all the subsequent Swing events (including invokeLater() calls) are executed on the right thread.

Thanks,

Artem

On 2/3/2014 3:16 PM, Hendrik Ebbers wrote:
Hi,
I’m currently trying the experimental support of the javafx.embed.singleThread 
flag to mix the EDT and JFX Application Thread. Therefore I created a demo 
application. But when I start the app the following exception is thrown:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Not on 
FX application thread; currentThread = AWT-EventQueue-0

I think I’m doing something wrong but currently I have no idea why this is not 
working. Any ideas?

I’m using the folioing JavaFX version:

java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b123)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b65, mixed mode)

Here is the code of the demo application:

public class JFXPanelDemo1 {

     private static JButton swingButton;
     private static Button jfxButton;

     public static void main(String[] args) {


         SwingUtilities.invokeLater(() -> {
             JFrame swingFrame = new JFrame("Integrate JavaFX in Swing");
             swingFrame.getContentPane().setLayout(new BorderLayout());
             swingButton = new JButton("I'm a Swing button");
             swingFrame.getContentPane().add(BorderLayout.NORTH, swingButton);

             swingButton.addActionListener((e) -> {
                 jfxButton.setDisable(!jfxButton.isDisable());
             });

             JFXPanel jfxPanel = new JFXPanel();
             swingFrame.getContentPane().add(BorderLayout.CENTER, jfxPanel);

             jfxButton = new Button("I'm a JavaFX button");
             StackPane jfxPane = new StackPane(jfxButton);
             Scene jfxScene = new Scene(jfxPane);
             jfxPanel.setScene(jfxScene);

             jfxButton.setOnAction((e) -> {
                 swingButton.setEnabled(!swingButton.isEnabled());
             });

             swingFrame.setVisible(true);
         }
         );

     }
}

Reply via email to