I tried to use Swing Components in JavaFX with the SwingNode:
public class MyTest extends Application {
@Override
public void start(Stage stage) {
final SwingNode swingNode = new SwingNode();
FlowPane pane = new FlowPane();
Button btn = new Button("1");
btn.setVisible(false);
pane.getChildren().add(btn);
createAndSetSwingContent(swingNode);
pane.getChildren().add(swingNode);
stage.setScene(new Scene(pane, 100, 50));
stage.show();
btn.setVisible(true);
}
private void createAndSetSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
swingNode.setContent(new JButton("Click me!"));
}
});
}
public static void main(String[] args) {
launch(args);
}
}
After starting the application some parts of the window (the background and the JavaFX button) are black:
After a resize (or an other update) the window is shown correctly:
Why is it like this and how can I fix it?