2

嗨,我有一个基于 Swing 的 Java 应用程序,该应用程序在我的计算机上的 Kali 发行版中运行良好

我想在基于 ArchLinux 的 raspBerry pi3 b+ 中运行这个应用程序 jar,我成功安装了支持 LXDE 的操作系统,我还使用了 openjdk 完全支持 1 8 171

使用命令 java -jar dvr.jar 运行时,我面临从字体管理器引发的 NullPointerException

java.lang.NullPointerException
    at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
    at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
    at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
    at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
    at sun.font.SunFontManager$2.run(SunFontManager.java:431)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.font.SunFontManager.<init>(SunFontManager.java:376)
    at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
    at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
    at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
    at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
    at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
    at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:245)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1662)
    at javax.swing.tree.DefaultTreeCellRenderer.getPreferredSize(DefaultTreeCellRenderer.java:565)
    at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2815)
    at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:492)
    at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1360)
    at javax.swing.tree.VariableHeightLayoutCache.rebuild(VariableHeightLayoutCache.java:738)
    at javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLayoutCache.java:109)
    at javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:412)
    at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3414)
    at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
    at java.awt.Component.firePropertyChange(Component.java:8428)
    at javax.swing.JTree.setModel(JTree.java:882)
    at javax.swing.JTree.<init>(JTree.java:670)
    at javax.swing.JTree.<init>(JTree.java:645)
    at javax.swing.JTree.<init>(JTree.java:629)
    at com.wanasis.vlc.view.JCheckBoxDragableTree.<init>(JCheckBoxDragableTree.java:88)
    at com.wanasis.vlc.view.JCheckBoxDragableTree.<init>(JCheckBoxDragableTree.java:72)
    at com.wanasis.vlc.control.MainFrameBuilder.build(MainFrameBuilder.java:27)
    at com.wanasis.vlc.SwingMain$1.run(SwingMain.java:56)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

如何设置 swing LAF 以使用系统当前字体?

我试过了,但没有结果

UIManager.setLookAndFeel(
    UIManager.getSystemLookAndFeelClassName());
UIManager.getLookAndFeelDefaults()
.put("defaultFont", new Font("Arial", Font.BOLD, 14));
4

1 回答 1

1

归功于 - @Sergiy Medvynskyy -

我使用了 java 字体部分来了解这个想法

我使用 pacman 工具搜索了一些字体,pacman -Ss font然后在谷歌上搜索并选择了一组我想要的字体包,并将我的应用程序切换为使用该Times字体

注意:不要忘记通过 -Sy 更新 pacman pacman -Sy, -Ss 是一个包搜索工具,使用存储库后的包名称,/例如extra/mypack-alpha v.x.y.z安装mypack-alpha 使用 pacman -S mypack-alpha

于 2019-12-12T07:17:51.993 回答