JCanvas3D in JavaFX SwingNode created with negative Dimensions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JCanvas3D in JavaFX SwingNode created with negative Dimensions

MrFreeze
Hello everyone,

due to some reasons I needed to put a JCanvas3D in a JavaFX SwingNode, always resulting in the exception
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (-26) cannot be <= 0
	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
	at java.awt.image.BufferedImage.<init>(Unknown Source)
	at com.sun.j3d.exp.swing.JCanvas3D.createOffScreenBuffer(JCanvas3D.java:340)
It appears that the swing node calls the setBounds method at least twice, one time with the false dimensions (at creation time) and a second time once the component is finally placed. After trying around for several hours how to avoid the first call, I finally created my JCanvas3D with
 jCanvas3D = new JCanvas3D(gCT)  {
      @Override
      public void setBounds(int x, int y, int w, int h) {                    
         if (w<=0) w = 10;
         if (h<=0) h = 10;
         super.setBounds(x, y, w, h);
     }
 };
which solved the issue. Is there any better solution? If not, maybe this code should probably go into the JCanvas3D implementation ...

Best Greetings;
Mr. Freeze

PS: I was aware off InteractiveMeshs amzing work j3d meets jfx, but due to project internal reasons I had to stick to the SwingNode issue.
Reply | Threaded
Open this post in threaded view
|

Re: JCanvas3D in JavaFX SwingNode created with negative Dimensions

gouessej
Administrator
Hi

I'd like to have a better way to detect that we are "at creation time" but your workaround will be useful. Thank you for the feedback.
Julien Gouesse | Personal blog | Website