繁体   English   中英

物质L&F不工作

[英]Substance L&F not working

我想在我的Java应用程序中使用Substance L&F库,所以我下载了.jar文件并将它们添加到项目类路径中。 然后我想在应用程序的main()函数中设置L&F,如下所示:

SwingUtilities.invokeAndWait(new Runnable()
{
    @Override
    public void run()
    {
        try
        {
            // Substance
            String skin = "org.pushingpixels.substance.api.skin.SubstanceGraphiteAquaLookAndFeel";
            SubstanceLookAndFeel.setSkin(skin);
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
        }
        catch(Exception e)
        {
            System.err.println("Can't initialize specified look&feel");
            e.printStackTrace();
        }
    }
});

这是在创建JFrame之前完成的。 但是,即使没有抛出异常,也没有任何反应,GUI在默认的Swing L&F中呈现。

我在这里缺少什么想法?

编辑
而不是SubstanceLookAndFeel.setSkin(skin); 打电话我用UIManager.setLookAndFeel(skin);试了一下UIManager.setLookAndFeel(skin); 代替。 这仍然不起作用,但至少我现在得到一个例外:

org.pushingpixels.substance.api.UiThreadingViolationException:
必须在事件调度线程上进行状态跟踪

是不是通过invokeAndWait()调用它解决了?

编辑-2
好的,所以问题是不同的。 创建JTable时抛出异常,而不是在设置L&F时抛出异常。 通过EventQueue.invokeLater()调用JFrame构造函数(然后基本上运行整个应用程序),我能够解决问题 - L&F现在正确呈现了。 但是之前我从来没有这样做过,用这种方式“保存”(用Java术语有效)吗?

设置Substance LaF时有一个小技巧。 你必须调用UIManager.setLookAndFeel(new SubstanceGraphiteAquaLookAndFeel()); 在你调用UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceGraphiteAquaLookAndFeel"); 所以,设置如下:

public class App {

    public static void main(String [] args) {
        try {

            UIManager.setLookAndFeel(new SubstanceGraphiteAquaLookAndFeel());
            UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceGraphiteAquaLookAndFeel");    

        } catch (ClassNotFoundException | InstantiationException
                | IllegalAccessException | UnsupportedLookAndFeelException e1) {
            e1.printStackTrace();
        }
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                //Your GUI code goes here..
            }
        });

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM