SWT-AWT high DPI problems with Java 11

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

SWT-AWT high DPI problems with Java 11

This post was updated on .
Hello there,

I am facing problems when I updated Java on our application from version 8 to 11. I am aware of this HighDPI issues and that is why I also updated to newest JOGAMP libs (2.5.0).

I have Eclipse E4 RCP application, which works fine with SWT widgets. My GLCanvas is inside AWT frame that is created inside SWT composite using SWT_AWT bridge. Here is code snippet, how it is created (it is simplified code, I removed stuff that I do not consider important. I can provide more code if needed):

      // Composite glComposite comes as argument to this method - parental composite
      GLProfile profile = GLProfile.getDefault(GLProfile.getDefaultDevice());
      GLCapabilities capabilities = new GLCapabilities(profile);

      com.jogamp.opengl.awt.GLCanvas glCanvasAWT = new com.jogamp.opengl.awt.GLCanvas(capabilities);

      Frame frame = SWT_AWT.new_Frame(glComposite);
      frame.setLayout(new java.awt.CardLayout());
      frame.add(glCanvasAWT, "GL_RENDER");

     frame.addComponentListener(new ComponentListener()
        public void componentResized(ComponentEvent e)
          Display.getDefault().syncExec(() ->
            System.out.println("Composite bounds: " + glComposite.getBounds());
            System.out.println("Frame bounds: " + frame.getBounds());
            System.out.println("AWT canvas bounds: " + glCanvasAWT.getBounds());

       // other ComponentListener methods


When I resize my application, componentResized(ComponentEvent) is called and bounds of each object is printed to console. For some reason, they are not all the same - AWT frame and AWT Canvas bounds are smaller than SWT composite bounds and ratio between those bounds is corresponding to current monitor zoom (e.g.: Monitor zoom is 125%, SWT Composite bounds are 1000x1000 -> AWT frame bounds are 800x800).

This desynchronization happens only with zoom higher than 100% and it is of course causing my scene to "overlap" behind application. And of course, scene events are not working as expected when bounds are not correct.

Am I missing something in my code, is it somehow possible to fix this? Same code works fine on java 8 - bounds are same for SWT and AWT widgets.

Thank you for your answers in advance.

My versions:
   JOGAMP 2.5.0
   SWT 3.109
   Adoptium Terumin jdk 11.0.20
Reply | Threaded
Open this post in threaded view

Re: SWT-AWT high DPI problems with Java 11

Sven Gothel
Hi Thomas,

the AWT GLCanvas inside an SWT scenario .. phew, indeed,
this is probably not addressed as the zoom factor probably is not forwarded
to the AWT component itself.

Could you try our own SWT GLCanvas and/or NewtCancasSWT instead?

Alternatively, if this is important .. we might need to think about forwarding
the zoom factor .. or you must manually apply it.
IMHO this is not on our turf, but AWT/SWT integration.
Reply | Threaded
Open this post in threaded view

Re: SWT-AWT high DPI problems with Java 11

Hi Sven,

yeah, you are right. I tested this with small app, where I used SWT - AWT Bridge. When rezooming this app, bounds are desynchronized.

I tried to investigate, how to forward DPI settings to AWT but I was not successful. :/ What do you mean by manually applaying it?

We also use SWT canvas in some cases and this one works fine. But for some performance stuff, AWT canvas used to be better.

Thank you.