jMonkeyEngine / jMonkeyEngine/jmonkeyengine
Canvas embedded in Swing application renders at wrong scale on HiDPI
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 14
Description
I am trying to embed JMonkeyEngine into a Swing application and noticed the Canvas is rendering at a different scale on HiDPI displays, the screenshot below is on a 200% scale display. I set a custom background color on the canvas to make sure it has the correct dimensions.

I combined the TetsGltfLoading class with some sample code for embedding the canvas:
package nl.rp.ddd.jme;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
public class JmeTests {
public JmeTests() {
final JFrame frame = new JFrame();
frame.setTitle("JME 3 Tests");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
AppSettings settings = new AppSettings(true);
settings.setWidth(800);
settings.setHeight(600);
settings.setVSync(true);
TestGltfLoading canvasApplication = new TestGltfLoading();
canvasApplication.setSettings(settings);
canvasApplication.setDisplayStatView(false);
canvasApplication.setDisplayFps(false);
canvasApplication.createCanvas();
JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();
ctx.setSystemListener(canvasApplication);
Dimension dim = new Dimension(800, 600);
ctx.getCanvas().setPreferredSize(dim);
ctx.getCanvas().setBackground(new Color(50, 50, 100));
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(ctx.getCanvas(), BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
System.setProperty("org.lwjgl.opengl.Display.enableHighDPI", "true");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new JmeTests();
}
});
}
}
I tested this with 3.3.2-stable, jme3-lwjgl (embedding a canvas failed with jme3-lwjgl3), java 10 and java 11 runtimes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the report with the provided JmeTests example, JmeCanvasContext, AppSettings, and createCanvas on a 200% HiDPI display using Java 10 or 11. Compare the Swing canvas dimensions and rendered scale with the configured 800x600 size; done means the embedded canvas renders at the expected scale.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- computer-graphics, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100