Run the following code. The initial visible color is green but it should be red (the fill color specified on the content). When manually resizing the window, the content appears.
import java.awt.Color;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class SwingNodeResizeContent extends Application {
private SwingNode swingNode;
private JPanel jPanel;
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
root.setStyle("-fx-background-color: #00FF00;");
swingNode = new SwingNode();
swingNode.setStyle("-fx-background-color: #0000FF;");
root.getChildren().add(swingNode);
Scene scene = new Scene(root, 800, 800);
stage.setScene(scene);
stage.show();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jPanel = new JPanel();
jPanel.setBackground(Color.RED);
swingNode.setContent(jPanel);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
import java.awt.Color;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class SwingNodeResizeContent extends Application {
private SwingNode swingNode;
private JPanel jPanel;
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
root.setStyle("-fx-background-color: #00FF00;");
swingNode = new SwingNode();
swingNode.setStyle("-fx-background-color: #0000FF;");
root.getChildren().add(swingNode);
Scene scene = new Scene(root, 800, 800);
stage.setScene(scene);
stage.show();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jPanel = new JPanel();
jPanel.setBackground(Color.RED);
swingNode.setContent(jPanel);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
- duplicates
-
JDK-8115231 [SwingNode] : SwingNode has always zero size
-
- Closed
-
-
JDK-8124682 [SwingNode] : Button and text field is not painted
-
- Closed
-