我正在将我的 Maven JavaFX 应用程序从 Java 8 迁移到 Java 11。我将 pom.xml 中的插件更新为最新的(兼容 Java 11 的)插件。编译运行良好,在“目标”文件夹下的正确目录中为我提供了 jar 以及所有依赖项和模块,但是当我尝试运行 jar 文件时,我收到了可怕的“缺少 JavaFX 应用程序类”错误。无论我如何尝试更改插件配置 - 我总是收到此错误消息,并且应用程序将无法运行。
现在,更多发现: 1. 主类确实位于类下的正确文件夹和 jar 中。2. Manifest 文件位于正确的位置,并且包含主类属性(在 Java 8 下工作正常)。
这是相关部分
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<release>11</release>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerVersion>11</compilerVersion>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
<manifestEntries>
<JavaFX-Application-Class>${mainClass}</JavaFX-Application-Class>
</manifestEntries>
</archive>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-libs</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<includeScope>runtime</includeScope>
<excludeGroupIds>org.openjfx</excludeGroupIds> …Run Code Online (Sandbox Code Playgroud) 在我的 JavaFX 项目中,我包含了一个使用Linear.Flow. 对于我的 WizardPane 之一,我希望将Next按钮的禁用属性绑定到布尔属性。(更具体地说,如果文本字段为空,则应禁用该按钮)。
但是,我无法找到任何解决方案。(此处提供的可能解决方案对我不起作用)。
这是我的向导窗格:
private WizardPane getName() {
TextField textField = new TextField();
textField.requestFocus();
final WizardPane namePane = new WizardPane();
namePane.setHeaderText("Choose Name for File");
final GridPane grid = new GridPane();
grid.add(new Label("File Name:"), 0, 0);
grid.add(textField, 1, 0);
namePane.setContent(grid);
return namePane;
}
Run Code Online (Sandbox Code Playgroud)
我绑定disabled属性的失败尝试如下:
@Override
public void onEnteringPage(Wizard wizard) {
this.getButtonTypes()
.stream()
.filter(type -> type.getButtonData().equals(ButtonBar.ButtonData.NEXT_FORWARD))
.map(this::lookupButton)
.findFirst()
.ifPresent(next -> next.disableProperty().bind(textField.textProperty().isEmpty()));
}
Run Code Online (Sandbox Code Playgroud)
任何建议都非常感激。谢谢!
对于熟悉 Java 的开发人员来说,JavaFX 是一种非常强大的创建 GUI 应用程序的方法,但在 Java 较新版本中,javaFX 没有发生任何更新。而在 Java 13 中,之前的一些功能并未包含在内。
作为初学者,我应该学习 javaFX 或 Swing 或任何其他方式来创建 java GUI 应用程序
可以使用javafx.stage.Stage.setResizing(boolean)方法更改 JavaFX 阶段的可调整大小状态。
问题
是否有可能允许仅水平或仅垂直调整大小?
有诸如Stage.setMaxWidth、Stage.setMaxHeight、之类的方法Stage.setMinWidth,Stage.setMinHeight但它们只能用于控制固定大小阶段的大小调整(width = minWidth = maxWidth 例如通过设置禁止水平调整大小)。
我正在与 TMC 一起为 NetBeans 课程开展一些学校项目。我正在练习使用 javafx。到目前为止,Javafx 一直运行顺利。我正在尝试“导入 javafx.scene.media.AudioClips;” 它说包“javafx.scene.media”不存在。如果我尝试构建该项目,我会收到以下错误消息:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Osa14_08.Hurraa: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:185)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:181)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1215)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:188)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 11 more
Run Code Online (Sandbox Code Playgroud)
我试图为此找到解决方案(向 pom 添加内容,下载 javafx 并将其添加到 JDK),但没有一个有效。我认为寻找和执行任何解决方案的问题在于我对这些事情如何运作的理解程度。
我正在尝试从外部 URL 加载图像并将其设置为ImageView使用 JavaFX。在 IDE 中运行时它总是有效,但当我使用 JLink 构建项目时,只有来自几个 URL 的图像有效。
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:313)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:293)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:186)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1144)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1055)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:395)
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
Run Code Online (Sandbox Code Playgroud)
最初,我认为问题是我没有设置 a User-Agent,所以我将代码修改为以下内容:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:313)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:293)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:186)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1144)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1055)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:395)
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567) …Run Code Online (Sandbox Code Playgroud) 想要将 JavaFX 图表的 x 轴刻度标签设置text-alingment为。center
我有一个带有日期的 JavaFX NumberAxis X 轴,使用多行文本作为刻度标签。使用 . 将刻度标签设置为“dd/MMM\YYYY”或“HH:mm\ndd/MMM” AxisX.setTickLabelFormatter(getTimeAxisString())。用户函数 getTimeAxisString() 提供刻度标签的格式化字符串。默认情况下,这会导致文本左对齐,如下图所示:
轴刻度标签
是否有 JavaFx 方法可以更改此处的文本排列?我可以为刻度标签分配 CSS 类吗?
我想实现这一目标: https://images.app.goo.gl/rH7o4hssPt1mLeEM9
目前我已经制作了一个进度条-fx-accent: #87CEEB;
但我希望它是线性渐变:
linear-gradient(to right, #87CEEB, #2980b9);
我怎样才能做到呢?
我正在使用 IntelliJ 和OpenJDK 17创建 JavaFX 应用程序。项目语言级别设置为17。创建 JAR(构建工件)后,我尝试使用JRE 1.8.0_311执行它。当我这样做时,我收到此错误:
java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
Error: A JNI error has occurred, please …Run Code Online (Sandbox Code Playgroud) 安装OpenJDK和Temurin桶(测试第一个,然后测试另一个)后,在从终端运行一个简单的示例 javafx 应用程序时,我仍然遇到这样的错误:
Example.java:1: error: package javafx.application does not exist
Run Code Online (Sandbox Code Playgroud)
在我看来,JavaFX 并未包含在 macOS 的 OpenJDK 中,至少是 Homebrew 版本中,但它应该包含在内。
我正在安装的版本是 17,在这两个方面都是如此。
我可以做什么来解决这个问题?(我特别不想安装 Oracle 的 JDK,以避免未来高额的许可费用或潜在的诉讼,而 Oracle 以此而闻名。)