如何设置Nimbus的主要外观 [英] How to set Nimbus look and feel in main

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

问题描述

我只是在学习Java,但仍然无法解决我遇到的这个小问题

I am just learning Java and still have not been able to sort this little problem I have

我的弹出式日历使用了Nimbus的外观和感觉,但我有面板和容器Jtables
使用Java的外观 - 我试图让每个GUI屏幕/窗口都使用
nimbus的外观和感觉,Merky建议将愚蠢的代码放在我的主要$ b $中b使每个后续屏幕都具有Nimbus的外观和感觉,但我无法让它工作
所以有人可以告诉我应该把这段代码放在哪里以及如何使用。

My pop up Calendar uses Nimbus look and feel but I have panels and container Jtables that use Java's look and feel - I am trying to make every GUI screen/ window use the nimbus look and feel and it was suggested by Merky to put the foolowing code in my main to make every subsequent screen have the Nimbus look and feel but I cannot get it to work so can someone tell me where and how I should put this code PLEASE.

public static void main(String args[])
    {


        SA md=new OptraderSA("Copyright© 2010 Simon Andi");

        Dimension sd=Toolkit.getDefaultToolkit().getScreenSize();

        md.setLocation(sd.width/2-400/2, sd.height/2-400/2);
        md.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /*Suggested Code*/   
         try {

          for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
             UIManager.setLookAndFeel(info.getClassName());
                        System.out.println("CHOSEN THIS");
              break;
         }
         else{
                    UIManager.setLookAndFeel  ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
          }
        }

        } catch (Exception e) {
        / If Nimbus is not available, you can set to another look and feel.

            Cant get it to compile or work.

}

会提供一些帮助吗
Simon

Would apprciate some help Please Simon

推荐答案

这是我在启用Nimbus L& F的主要方法中所做的。

This is what I do in my main method to enable Nimbus L&F.

public static void main(String[] args) {
try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, fall back to cross-platform
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception ex) {
        // not worth my time
    }
}
new Controller();
}

您需要确保先使用Nimbus L& F配置UIManager你启动swing事件调度线程(在调用view.setVisible(true)之前)。希望有所帮助。

You need to be sure to configure the UIManager with the Nimbus L&F before you start the swing event dispatch thread (before calling view.setVisible(true)). Hope that helps.

这篇关于如何设置Nimbus的主要外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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