0 Replies Latest reply: Feb 23, 2010 9:04 AM by 800557 RSS

    addPropertyChangeListener + Nimbus = java.lang.NullPointerException

    800557
      Hi. I've been following a tutorial to build a JavaBean so that I can use it in NetBeans. The code below is the general structure that I have in my bean and it works fine on all LAFs except in Nimbus:
      import java.beans.*;
      
      public class ExpBean extends javax.swing.JPanel implements java.io.Serializable {
      
          private PropertyChangeSupport propertySupport;
          public static final String PROPERTY1 = "prop1";
      
          public ExpBean () {
              propertySupport = new PropertyChangeSupport(this);
              initComponents(); // NetBeans generated code to initialize components
          }
      
          @Override
          public void addPropertyChangeListener(PropertyChangeListener listener) {
              propertySupport.addPropertyChangeListener(listener);
          }
          @Override
          public void removePropertyChangeListener(PropertyChangeListener listener) {
              propertySupport.removePropertyChangeListener(listener);
          }
      
          private void formPropertyChange(java.beans.PropertyChangeEvent evt) {
              if (evt.getPropertyName().equalsIgnoreCase(PROPERTY1)) {
                  // some code
              }
          }
      
      }
      I've searched the net for fixes but there's almost no information about this and the few there is is way over my head. I can use my bean with Nimbus if I remove the methods addPropertyChangeListener and removePropertyChangeListener but if I do that, I can't change properties in design time in NetBeans. If I don't remove them and I try to use Nimbus, I get:
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException        
              at pt.gsc.dev.beans.ExpBean.addPropertyChangeListener(SmigDatePicker.java:90)
              at javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:49)
              at javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:38)
              at javax.swing.JComponent.setUI(JComponent.java:662)
              at javax.swing.JPanel.setUI(JPanel.java:136)
              at javax.swing.JPanel.updateUI(JPanel.java:109)
              at javax.swing.JPanel.<init>(JPanel.java:69)
              at javax.swing.JPanel.<init>(JPanel.java:92)
              at javax.swing.JPanel.<init>(JPanel.java:100)
              at pt.gsc.dev.beans.ExpBean.<init>(ExpBean.java:26)
              at pt.gsc.dev.comercial.contactos.FiltroContactos.initComponents(FiltroContactos.java:154)
              at pt.gsc.dev.comercial.contactos.FiltroContactos.<init>(FiltroContactos.java:20)
              at pt.gsc.dev.comercial.contactos.Contactos.<init>(Contactos.java:34)
              at pt.gsc.dev.MenuModular$15.actionPerformed(MenuModular.java:314)
              at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
              at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
              at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
              at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
              at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
              at java.awt.Component.processMouseEvent(Component.java:6263)
              at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
              at java.awt.Component.processEvent(Component.java:6028)
              at java.awt.Container.processEvent(Container.java:2041)
              at java.awt.Component.dispatchEventImpl(Component.java:4630)
              at java.awt.Container.dispatchEventImpl(Container.java:2099)
              at java.awt.Component.dispatchEvent(Component.java:4460)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
              at java.awt.Container.dispatchEventImpl(Container.java:2085)
              at java.awt.Window.dispatchEventImpl(Window.java:2478)
              at java.awt.Component.dispatchEvent(Component.java:4460)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
      On the other hand, I use other 3rd party beans just fine with Nimbus and they all have properties I can change at design time in NetBeans so they must be doing it differently. So how should I code this in order for this to function with Nimbus?