Java运行时外观 [英] Java look and feel at runtime

查看:115
本文介绍了Java运行时外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的GUI(带有按钮的纯Jframe),并且使用Nimrod改变了外观.新的l& f是一个黑暗的主题,我会在运行时更改.

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.

但是,当运行GUI时,在很短的时间内,GUI的背景很亮,然后应用了新的深色l& f.

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.

我认为造成这种短暂的闪烁的原因是在运行时,在应用新的l& f之前短暂地显示了默认的l& f.

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.

如果我在运行后用按钮更改L& f,似乎不会发生.

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

那么,其他人对此有任何经验吗?有没有可能的解决方法?隐藏JFrame,直到应用新的l& f?

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)
        {

        }       

    }   

此外,如果需要Nimrod,则可以在此处获取: http://www.mediafire.com/?l9pytbooenmemgc

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

非常感谢任何帮助.

推荐答案

关于 SwingUtilities .updateComponentTreeUI(frame);

这篇关于Java运行时外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆