gpt4 book ai didi

JavaFX : Why doesn't the setContent method of SwingNode with a JComponent parameter accept a JPanel?

转载 作者:太空宇宙 更新时间:2023-11-04 07:23:29 25 4
gpt4 key购买 nike

我有以下代码:

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 的子类时才有效,但不适用于其子类,例如 JFrameJPanel。怎么了?

最佳答案

它告诉您 JFrame 不是 JComponent。你猜怎么了?没错。

亲自看看:JFrame API

关于JavaFX : Why doesn't the setContent method of SwingNode with a JComponent parameter accept a JPanel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18937299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com