我正在一个Java项目小组工作,目标是使用JavaFX设计GUI . GUI的主要结构是完整的,它可以很好地工作,直到我们使用CSS来定制按钮和文本框等的一些图形细节 . The GUI runs without any problems on Windows and MAC, but when I try to run it on Ubuntu, a problem occurs.
As soon as I get the GUI up and running via Netbeans on Ubuntu, some details of the elements adjusted via .css files are no longer displayed. 几个按钮和文本框上出现此问题 .
可以构建和执行Java项目而不会出现错误消息 . 我只收到一些警告,但它们在Windows或MAC下不会引起任何问题 .
During the build:
Note: /.../.../.../.../nameOfClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint: unchecked for details.
Detected JavaFX Ant API version 1.3
Launching <fx:jar> task from /usr/lib/jvm/jdk1.8.0_161/jre/../lib/ant-javafx.jar
Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing.
Please set manifest.custom.codebase property to override the current default non-secure value '*'.
Launching <fx:deploy> task from /usr/lib/jvm/jdk1.8.0_161/jre/../lib/ant-javafx.jar
No base JDK. Package will use system JRE.
No base JDK. Package will use system JRE.
jfx-deployment-script:
jfx-deployment:
jar:
jfx-rebuild:
BUILD SUCCESSFUL (total time: 3 seconds)
When running:
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX runtime of version 8.0.161
通过Scenebuilder中的路径设置对.css文件的访问 . Scenebuilder将路径直接粘贴到.fxml文件中 . 如:
<AnchorPane prefHeight="500.0" prefWidth="400.0" style="-fx-background-color: #EEEEEE;" stylesheets="@../styleSheets/loginStyle.css" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="packagename.login.LoginController">
.css文件的内容:
/*
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
*/
.button {
-fx-background-color: #007399;
-fx-text-fill: #FFFFFF;
-fx-stroke: #FFFFFF;
}
.button:hover{
-fx-background-color: #328fad;
}
.button:pressed{
-fx-background-color: #005c7a;
}
有趣的是,只要我在场景构建器中打开.fxml文件,一切都会正确显示 . 但是当我在Ubuntu上运行Netbeans的GUI时,按钮看起来不同,或者它们没有显示 .
My Setup:
Ubuntu 17.10
Netbeans 8.2 with Java:1.8.0_161;运行时:Java(TM)SE运行时环境1.8.0_161-b12;
JavaFX Scene Builder 9.0.1构建信息版本9.0.1 Java版本:9 181,Oracle Corporation
我的本地Java版本“java -version”:java版“1.8.0_161”Java(TM)SE运行时环境(版本1.8.0_161-b12)Java HotSpot(TM)64位服务器VM(版本25.161-b12,混合模式)
I have already tried the following solutions without success:
我尝试了不同的本地Java版本: - java-8-openjdk-amd64-java-9-openjdk-amd64-jdk1.8.0_151-jdk1.8.0_161-jdk-9.0.4
我更改了Java版本的Netbeans:/netbeans-8.2/etc/netbeans.conf我尝试了上面的所有这些Java版本 . Netbeans只运行jdk 1.8 *稳定,但我的问题没有解决办法 . 我不认为问题是因为Java版本 . 我的同事在Windows和MAC上使用相同的Java,Netbeans和Scenebuilder版本,它适用于它们 .
我已将我的桌面环境从gnome更改为xfce,kubuntu和unity . 但问题还在继续 .
我通过git在另一台具有相同Ubuntu,Netbeans和Scenebuilder版本的笔记本电脑上克隆了该项目,问题也出现在这里 .
不幸的是我找不到javafx或类似的任何日志文件 .
如果有人有想法修复这个bug,我会非常高兴 .
最好的祝福
1 回答
最后我找到了解决方案 . 我使用了一个使用Scenebuilder创建的“Rectangle”对象 . 未选中“平滑”选项 . 这导致Linux机器下的错误 .
要解决此问题,请将“平滑”设置为“"true"”
“属性:矩形>特定>平滑