-1

I added substance theme to my swing application and tried to run it, and it works . but I keep getting this exception while running it. can someone tell me how to fix it?

Exception.....................................................................................

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at org.jvnet.substance.SubstanceTableUI$TableStateListener$2.run(SubstanceTableUI.java:1951)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Code.......................................................................................

   try {
        LookAndFeel look = new SubstanceDefaultLookAndFeel();
        UIManager.setLookAndFeel(look);
        SubstanceDefaultLookAndFeel.setCurrentTheme(new SubstanceBottleGreenTheme());
        SubstanceDefaultLookAndFeel.setCurrentWatermark(new SubstanceNoneWatermark());
        SubstanceDefaultLookAndFeel.setCurrentGradientPainter(new SimplisticSoftBorderReverseGradientPainter());
        new Login().setVisible(true);
   } catch (Exception e) {
        e.printStackTrace();
   }

1 Answers1

1

Be sure that you are explicitly creating your GUI on the event dispatch thread. I've run into this very problem with some Look and Feels when I did not do this. You do this by queuing up your start up code on the EDT via

SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    // start your GUI here
  }
});

i.e.,

SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    try {
        LookAndFeel look = new SubstanceDefaultLookAndFeel();
        UIManager.setLookAndFeel(look);
        SubstanceDefaultLookAndFeel.setCurrentTheme(new SubstanceBottleGreenTheme());
        SubstanceDefaultLookAndFeel.setCurrentWatermark(new SubstanceNoneWatermark());
        SubstanceDefaultLookAndFeel.setCurrentGradientPainter(
           new SimplisticSoftBorderReverseGradientPainter());
        new Login().setVisible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
  }
}

Edit, mKorbel is right -- the look and feel change should be on the EDT. Code changed to reflect this. Sorry for the mis-information.

Hovercraft Full Of Eels
  • 276,051
  • 23
  • 238
  • 346