MSketchPane exception with Synth look-and-feel in JDK 1.5

User 6ef33138f9

12-10-2005 15:05:06

Hello,





We're running JDK 1.5 and using the Synth look-and-feel. If you're not familiar with this, it's a new feature in JDK 1.5:


http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/package-summary.html





When using Synth, creating an MSketchPane fails with a NullPointerException. If we disable Synth (but still use 1.5), it works fine. We're using Marvin 3.5.7. Here's the stack trace:





Code:



Thread [main] (Suspended (exception java.lang.NullPointerException))


   chemaxon.marvin.sketch.swing.SketchPanel(chemaxon.marvin.common.swing.MolPanel).addPropertyChangeListener(java.beans.PropertyChangeListener) line: not available


   javax.swing.plaf.synth.SynthPanelUI.installListeners(javax.swing.JPanel) line: not available


   javax.swing.plaf.synth.SynthPanelUI.installUI(javax.swing.JComponent) line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(javax.swing.JComponent).setUI(javax.swing.plaf.ComponentUI) line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(javax.swing.JPanel).setUI(javax.swing.plaf.PanelUI) line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(javax.swing.JPanel).updateUI() line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(javax.swing.JPanel).<init>(java.awt.LayoutManager, boolean) line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(javax.swing.JPanel).<init>(boolean) line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(javax.swing.JPanel).<init>() line: not available


   chemaxon.marvin.sketch.swing.SketchPanel(chemaxon.marvin.common.swing.MolPanel).<init>(java.awt.Component, int, chemaxon.marvin.common.UserSettings, int[]) line: not available


   chemaxon.marvin.sketch.swing.SketchPanel.<init>(java.awt.Component, int, int, javax.swing.JRootPane, chemaxon.marvin.common.UserSettings) line: not available


   chemaxon.marvin.beans.MSketchPane.<init>(chemaxon.marvin.common.UserSettings, boolean) line: not available


   chemaxon.marvin.beans.MSketchPane.<init>() line: not available








As you can see, when Synth is activated, some additional calls are made in JPanel.setUI (which is called from the JPanel constructor). Among other things, the Synth UI code calls addPropertyChangeListener on the panel that's being created. Marvin's MolPanel class overrides this method. My guess is that MolPanel.addPropertyChangeListener doesn't expect to be called until its constructor is complete.





Unfortunately we don't have a good workaround, since Synth must be turned on or off for the entire application: there's no way (that I know of) to disable it just for the MSketchPane.





By the way, it's possible that this is the same problem reported here:


http://www.chemaxon.com/forum/ftopic854.html





Thank you,


Chris

ChemAxon 7c2d26e5cf

12-10-2005 16:54:56

Can you send me an example? An example would help us a lot for the debugging.

User 6ef33138f9

12-10-2005 18:44:17

Here's a small example program. It doesn't really matter what you define in the Synth XML stream -- you just have to have something there so it's a valid Synth style. If you comment out the line to UIManager.setLookAndFeel(), the look-and-feel is not installed and it works fine.





Thanks,


Chris





Code:
import java.io.StringBufferInputStream;





import javax.swing.UIManager;


import javax.swing.plaf.synth.SynthLookAndFeel;





import chemaxon.marvin.beans.MSketchPane;





public class MSketchPaneTest


{


   public static void main(String[] args) throws Exception


   {


      SynthLookAndFeel synth = new SynthLookAndFeel();


      synth.load(new StringBufferInputStream("<synth><style id=\"panel\"><state><color type=\"BACKGROUND\" value=\"#3A3A3B\" /></state></style><bind style=\"panel\" type=\"region\" key=\"Panel\"/></synth>"), MSketchPaneTest.class);


      UIManager.setLookAndFeel(synth);


      MSketchPane pane = new MSketchPane();


   }


}


ChemAxon 7c2d26e5cf

13-10-2005 15:31:56

Thanks for the example. I will try it.

User 6ef33138f9

19-10-2005 15:23:10

Hi Tamas,





Any update on this problem?





Thank you,


Chris

ChemAxon 7c2d26e5cf

20-10-2005 08:28:45

Yes, I have fixed the above bug. Now, I am working on a patch release where this bug fix will be available.

User 6ef33138f9

31-10-2005 21:19:31

Hello Tamas,





Do you know when your patch release will be available?





Thanks again for your help with this!





Chris

ChemAxon 7c2d26e5cf

02-11-2005 10:22:07

In a few days.

User 6ef33138f9

02-12-2005 22:13:45

Hi Tamas, is the patch available now? If so, please let me know how to obtain it.





Thank you!


Chris

ChemAxon 7c2d26e5cf

02-12-2005 22:37:00

Yes, it is already available: Marvin 4.0.3 includes the bug fix.


You can download it from the following URL:


http://www.chemaxon.com/marvin/do-download-marvinbeans.html