【发布时间】:2020-12-02 21:18:06
【问题描述】:
我正在尝试使用 FXCanvas 将 JavaFX 集成到 SWT 应用程序中。供参考,我关注this oracle guide
在我的 IDE 中,这段代码显示错误
/* Create an FXCanvas */
final FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
getScene().getWindow().sizeToScene();
int width = (int) getScene().getWidth();
int height = (int) getScene().getHeight();
return new Point(width, height);
}
};
错误:
(是的,我已经导入了正确的 Point 类:org.eclipse.swt.graphics.Point):
'computeSize(int, int, boolean)' in 'Anonymous class derived from javafx.embed.swt.FXCanvas' clashes with 'computeSize(int, int, boolean)' in 'javafx.embed.swt.FXCanvas'; attempting to use incompatible return type
但是,我认为这不是根本原因...因为当我尝试构建项目 (maven) 时出现此错误: p>
package javafx.embed.swt does not exist。我认为这是真正的问题。
所以在做了一些研究之后,我检查了一些东西,首先,jfxswt jar 看起来应该可以访问:
我什至尝试将 JAR 作为库手动添加到我的模块中,但仍然无法正常工作。
这是我的 pom.xml,(我故意匿名了某些信息)
我还要提一下,我已经在一个没有任何 maven 依赖项的新项目中尝试过这个,并且只是手动添加了 swt 之类的库,但出现了同样的错误。
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</parent>
<artifactId></artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name></name>
<description></description>
<dependencies>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-ui-swt</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>jface</artifactId>
<version>3.3.0-I20070606-0010</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project>
我错过了什么,有什么想法吗?
【问题讨论】:
-
你能分享你的
pom.xml吗? (我假设它是一个 Maven 项目,因为你用它来标记它。) -
@Gebezs 在原始帖子中添加了 pom 和更多信息。
-
pom.xml定义的 java 版本是什么?它是在父级中定义的吗?我正在寻找maven.compiler.target和maven.compiler.source值以及maven-compiler-plugin配置。因为这些类应该包含在 jdk 中,并且零依赖模块也会发生同样的错误,这是我的最佳猜测。mvn help:effective-pom应该输出合并的配置。 -
@Gebezs
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target>两者都设置为 1.8,我的 jdk 也是如此