2

我想在我的 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);。这仍然不起作用,但至少我现在得到一个例外:

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

这不是通过调用这个来解决的invokeAndWait()吗?

EDIT-2
好的,所以问题有所不同。异常是在创建时抛出的JTable,而不是在设置 L&F 时。我能够通过调用JFrame构造函数(然后基本上运行整个应用程序)通过EventQueue.invokeLater(). 但我以前从未这样做过,这样做是否“保存”(在 Java 术语中有效)?

4

1 回答 1

4

设置的时候有个小技巧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..
            }
        });

    }
}
于 2013-10-30T23:15:58.433 回答