我真的不知道我缺少什么。我花了很多时间来阅读如何设置类路径,但这仍然行不通,在这一点上,我坚信这一定是一件微不足道的事情使我无法幸免。
我正在尝试使用秋千radiance libraries来更改秋千应用程序的外观。我按照build documentation制作了jar文件,当这些文件不起作用时,我下载并尝试了prebuilt binaries。我向开发人员提出了一个问题,并确认我正确地遵循了getting started instructions。演示代码如下:
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
public class Walkthrough extends JFrame {
public Walkthrough() {
super("Sample app");
this.setLayout(new FlowLayout());
this.add(new JButton("button"));
this.add(new JCheckBox("check"));
this.add(new JLabel("label"));
this.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR));
this.setSize(new Dimension(250, 80));
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(() -> {
Walkthrough w = new Walkthrough();
w.setVisible(true);
});
}
}
首先使用javac Walkthrough.java
编译代码,然后使用java Walkthrough
执行代码。这很好。接下来,使用辐射罐来更改外观,这是通过将swing.defaultlaf
属性设置为使用来自辐射的皮肤来完成的。这是行不通的地方。
我将所有所需的jar都复制到tmp
目录中,其中的演练示例紧邻tmp
。然后,我尝试如下运行该应用程序:
java -Dswing.defaultlaf=org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel -cp .:tmp/radiance-substance-2.5-SNAPSHOT.jar:tmp/radiance-trident-2.5-SNAPSHOT.jar:tmp/radiance-neon-2.5-SNAPSHOT.jar Walkthrough
这会导致以下异常:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot load org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel
at java.desktop/javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1406)
at java.desktop/javax.swing.UIManager.initialize(UIManager.java:1517)
at java.desktop/javax.swing.UIManager.maybeInitialize(UIManager.java:1483)
at java.desktop/javax.swing.UIManager.getUI(UIManager.java:1056)
at java.desktop/javax.swing.JPanel.updateUI(JPanel.java:126)
at java.desktop/javax.swing.JPanel.<init>(JPanel.java:86)
at java.desktop/javax.swing.JPanel.<init>(JPanel.java:109)
at java.desktop/javax.swing.JPanel.<init>(JPanel.java:117)
at java.desktop/javax.swing.JRootPane.createGlassPane(JRootPane.java:521)
at java.desktop/javax.swing.JRootPane.<init>(JRootPane.java:348)
at java.desktop/javax.swing.JFrame.createRootPane(JFrame.java:279)
at java.desktop/javax.swing.JFrame.frameInit(JFrame.java:258)
at java.desktop/javax.swing.JFrame.<init>(JFrame.java:225)
at Walkthrough.<init>(Walkthrough.java:7)
at Walkthrough.lambda$main$0(Walkthrough.java:23)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel生活在radiance-substance-2.5-SNAPSHOT.jar中。我已经确认它确实存在于jar tvf
中:
jar tvf radiance-substance-2.5-SNAPSHOT.jar | grep SubstanceBusinessLookAndFeel
548 Fri Feb 01 00:00:00 GMT 1980 org/pushingpixels/substance/api/skin/SubstanceBusinessLookAndFeel.class
因此,在这一点上,我确定我正在弄乱类路径,但我只是不知道是什么。我在Fedora 28上,我的Java版本是:
java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
答案 0 :(得分:1)
好吧,这与类路径无关,而与jar库本身无关。我观察到该字体在我的机器上默认不是抗锯齿的(Fedora 28,使用i3-gaps作为窗口管理器)。我想知道这是否有某种联系,并且对Java运行时环境字体做了一些阅读。本质上,字体看起来像这样:
但是使用以下系统属性启动应用程序:-Dawt.useSystemAAFontSettings=on
已修复:
事实证明,使用Radiance启动演练时设置此属性将使其起作用:
java -Dawt.useSystemAAFontSettings=on -Dswing.defaultlaf=org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel -cp .:tmp/radiance-substance-2.5-SNAPSHOT.jar:tmp/radiance-trident-2.5-SNAPSHOT.jar:tmp/radiance-neon-2.5-SNAPSHOT.jar Walkthrough
。
删除此属性会导致Java无法加载org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel的错误。
阅读here有更多信息。我假设,因为我已经自定义了Fedora 28设置(我不使用gnome),这是我没有运行Java用来获取系统默认值的gnome-settings-daemon
的原因。这在某种程度上是光辉的问题...?不确定。
我已将此通知给Radiance开发人员。如果/当他提供反馈时,我会更新此答案。
更新 开发人员确认这在库中存在错误。已修复。