Trying to style SwingNodes in JavaFX with GTKLookAndFeel freezes application

We have a Java application that used Swing, but we are migrating it to JavaFX. Therefore, we wrap the old Swing code into SwingNodes and replace them step-by-step.

Before migrating, the Swing application used com.sun.java.swing.plaf.gtk.GTKLookAndFeel as look-and-feel (default on Ubuntu). We used following code to set it (if available):

for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
  if (info.getClassName().equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel")) {
    UIManager.setLookAndFeel(info.getClassName());
  }
}

This worked fine. Yet, after switching to JavaFX, the call to UIManager.setLookAndFeel() freezes the application, and nothing happens. The manual setting of the look-and-feel is needed since we want to still style the Swing components that have not been migrated to JavaFX based on the GTKLookAndFeel.

Further info: This only does not work with com.sun.java.swing.plaf.gtk.GTKLookAndFeel, since it works when using javax.swing.plaf.metal.MetalLookAndFeel, javax.swing.plaf.nimbus.NimbusLookAndFeel or com.sun.java.swing.plaf.motif.MotifLookAndFeel.

What can we do to make it work with GTKLookAndFeel to style our Swing components in the SwingNodes?


Gui components need to be updated into gui threads.

Try one of the following:

SwingUtilities.invokeLater(() -> {
//commands
});

javafx.application.Platform.runLater(() -> {
//commands
});