Java 和 Windows Look &感觉

发布于 2024-10-20 07:48:53 字数 2361 浏览 2 评论 0原文

我制作了一个扫描图像的 swing 应用程序;每个图像都由一片叶子代表,我是一棵树,

我面临的问题是它抛出这个异常

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(XPStyle.java:513)
    at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(XPStyle.java:517)
    at com.sun.java.swing.plaf.windows.WindowsTreeUI$ExpandedIcon.getIconWidth(WindowsTreeUI.java:138)
    at javax.swing.plaf.basic.BasicTreeUI.drawCentered(BasicTreeUI.java:1580)
    at javax.swing.plaf.basic.BasicTreeUI.paintExpandControl(BasicTreeUI.java:1464)
    at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1206)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
    at javax.swing.JComponent.paintComponent(JComponent.java:763)
    at javax.swing.JComponent.paint(JComponent.java:1027)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

,我不知道为什么会出现这个异常 注意:我使用的是 Windows 外观

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

和 java 1.6_22 在windows-7下

I made a swing application that scans Images; and each Image represented by a leaf I a tree

the problem that I faced is that it throws this exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(XPStyle.java:513)
    at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(XPStyle.java:517)
    at com.sun.java.swing.plaf.windows.WindowsTreeUI$ExpandedIcon.getIconWidth(WindowsTreeUI.java:138)
    at javax.swing.plaf.basic.BasicTreeUI.drawCentered(BasicTreeUI.java:1580)
    at javax.swing.plaf.basic.BasicTreeUI.paintExpandControl(BasicTreeUI.java:1464)
    at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1206)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
    at javax.swing.JComponent.paintComponent(JComponent.java:763)
    at javax.swing.JComponent.paint(JComponent.java:1027)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
    at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

and I don't know why this appears
Note: I am using Windows Look and feel

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

and java 1.6_22
under windows-7

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找一个思念的角度 2024-10-27 07:48:53

试试这个:

//Set the look and feel to users OS LaF.
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

Try this:

//Set the look and feel to users OS LaF.
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文