{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreie4yi5md6flwnn5cbbyr2uflwmaedqk2s57s6oihjafwvxlo2cb6u",
    "uri": "at://did:plc:dxjzgxe7cvirxkwfjr2tjspt/app.bsky.feed.post/3mh44oy7h5ox2"
  },
  "path": "/t/resizing-canvas-in-a-swing-application/49436#post_2",
  "publishedAt": "2026-03-14T21:36:31.000Z",
  "site": "https://hub.jmonkeyengine.org",
  "textContent": "Never mind guys. Claude finally fixed it.\n\n\n\nHe added this fix to the main Swing app:\n```\n\n\n    public static void main(String[] args) {\n\n        // Fix HiDPI gap in JME3/LWJGL2 canvas: Java 9+ declares the process\n        // as DPI-aware, so the GL framebuffer is at physical pixel resolution\n        // but Canvas.getWidth()/getHeight() report logical pixels.  This causes\n        // glViewport to cover only (1/scale) of the framebuffer, leaving gaps\n        // on the right and bottom edges.  Disabling Java's DPI scaling makes\n        // logical == physical so the viewport fills the entire framebuffer.\n        System.setProperty(\"sun.java2d.uiScale\", \"1\");\n\n        // Compensate by letting FlatLaf scale the Swing UI independently.\n        // Toolkit.getScreenResolution() returns the OS DPI (e.g. 120 for 125%)\n        // via the native GetDeviceCaps API, unaffected by sun.java2d.uiScale.\n        try {\n            int dpi = Toolkit.getDefaultToolkit().getScreenResolution();\n            float scale = dpi / 96f;\n            if (scale > 1f) {\n                System.setProperty(\"flatlaf.uiScale\", String.valueOf(scale));\n            }\n        } catch (Exception ignored) {\n        }\n    ```\n",
  "title": "Resizing canvas in a Swing application"
}