Search code examples
javalook-and-feelnimbus

nimbus look and feel not appear after creating jar


nimbus look and feel not appear after creating jar when i run program in NetBeans at time Nimbus look & Feel work perfectly but when i create Jar and run Application from jar at time nimbus look & feel is not appear CODE:

public static void main(String[] args)
{

     boolean isNimbus = false;
try {

    for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
    {
        if ("Nimbus".equals(info.getName()))
        {
            UIManager.setLookAndFeel(info.getClassName());
            isNimbus = true;
            break;
        }
    }
    if(!isNimbus)
    {
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }

    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    Dashboard dashboardObj = new Dashboard();
}

Solution

  • If it works fine in NetBeans, but the LAF does not appear, when running a jar file, it probably means that the LAF library wasn't correctly discovered in the classpath. Since I don't know your setup, I can't really suggest the right answer. You could adjust your classpath settings when running the jar file (via jar -cp ...) or package your application as a single jar, with all the dependencies included - onejar is a convenient way to accomplish this.