我有以下代码:
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
或 JPanel
。怎么了?
它告诉您 JFrame
不是 JComponent
。你猜怎么了?没错。
亲自看看:JFrame API
我是一名优秀的程序员,十分优秀!