我有以下代码:
private void launchSingleRecordWindow() {
SwingNode swingNode = new SwingNode();
MainStageController.setContent(new AnchorPane(swingNode));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel webcamPanel = new WebcamPanel(selectedWebcam);
swingNode.setContent(webcamPanel);
}
});
}
但令我惊讶的是,字符串swingNode.setContent(webcamPanel);
不正确。
IntelliJ IDEA 说:
java: incompatible types: javax.swing.JPanel cannot be converted to javax.swing.JComponent
.
我试图创建单独的类,但它仅在它是 的子类时才有效JComponent
,但不适用于它的子类,例如JFrame
or JPanel
。怎么了?