I tried to use Swing Components in JavaFX with the SwingNode.
After starting the application some parts of the window (the background and the JavaFX button) are black.
After resizing the window, the window is repainted and looks like expected.
Here is my code:
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 resizing the window, the window is repainted and looks like expected.
Here is my code:
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);
}
}
- duplicates
-
JDK-8097328 [SwingNode]: Swing Nodes have serious rendering artifacts when first displayed on the primary Stage
-
- Resolved
-