Java look and feel at runtime

时间秒杀一切 提交于 2019-12-11 10:36:20

问题


I have a basic GUI (plain Jframe with a button) and I have changed the look and feel using Nimrod. The new l&f is a dark theme which I change at runtime.

However, when the GUI is run, for a very brief moment, the GUI has a bright background, and then the new dark l&f is then applied.

I assume what is causing this brief flash of brightness is that at runtime, the default l&f is showing briefly, just before the new one is being applied.

It's only a fraction of a second, but it's noticeable and quite annoying as it looks untidy.

It doesn't seem to happen if I change the l&f after runtime with a button.

So, does anyone else have any experience with this? Is there a possible workaround for this? Hide the JFrame until the new l&f is applied?

Here's my code if that helps:

    public static void main(String[] args) 
    {        
        setTheme();        

        NewJFrame njf = new NewJFrame();
        njf.setLocationRelativeTo(null);
        njf.setTitle("My First Swing Application");
        njf.pack();        
        njf.setVisible(true);                
    }

    static void setTheme()
    {
        NimRODTheme nt = new NimRODTheme();
        nt.setPrimary1( new Color(0,51,153));
        nt.setPrimary2( new Color(0,92,143));
        nt.setPrimary3( new Color(0,102,153));
        nt.setSecondary1( new Color(31,31,31));
        nt.setSecondary2( new Color(41,41,41));
        nt.setSecondary3( new Color(51,51,51));
        nt.setWhite( new Color(0,0,0));
        nt.setBlack( new Color(255,255,255));
        nt.setMenuOpacity(195);
        nt.setFrameOpacity(180);

        NimRODLookAndFeel NimRODLF = new NimRODLookAndFeel();
        NimRODLF.setCurrentTheme (nt);

        try
        {
            UIManager.setLookAndFeel(NimRODLF);       
        }
        catch(Exception e)
        {

        }       

    }   

Also, if nimrod is needed, you can get it here: http://www.mediafire.com/?l9pytbooenmemgc

Any help at all is greatly appreciated.


回答1:


Tutorial about Modifying the Look and Feel talking about method SwingUtilities.updateComponentTreeUI(frame);



来源:https://stackoverflow.com/questions/8953935/java-look-and-feel-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!