我最近决定从我正在使用的 JDK 切换到更新版本。(特别是从jdk1.8.0_261到jdk-14.0.2)。这次升级非常顺利,因为大多数功能都按照我预期的方式工作,并且我能够找到如何调整以适应任何不一样的情况。
然而,如标题所示,我在编写使用 Swing 的特定应用程序时遇到了问题。我的主显示器是 4k 显示器,我已将该显示器的 Windows 系统缩放设置为 200%。虽然每个其他 Swing 应用程序都可以缩放以匹配 DPI 设置,但对于这个特定的应用程序,我想禁用该缩放并按 1:1 绘制像素,尤其是当此应用程序是分布式的时。
有没有办法通过 VM 参数禁用这种自动缩放?或者有没有办法在调用 Swing 库之前在运行时禁用缩放?(类似于必须在对库进行任何其他调用之前对外观进行任何更改。)
以供参考:
这是我用来创建 JFrame 并创建我在其上绘制所有内容的图形对象的代码,这发生在此类和本问题范围之外的定时循环中。
public class ScreenManager {
private GraphicsDevice device;
private final JFrame frame;
private static ScreenManager instance;
public ScreenManager() {
instance = this;
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
this.device = env.getDefaultScreenDevice();
this.frame = new JFrame(game.getGame().gameName());
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.setUndecorated(true);
this.frame.setIgnoreRepaint(true);
this.frame.setResizable(false);
this.device.setFullScreenWindow(frame);
this.device.setDisplayMode(device.getDisplayMode());
this.frame.createBufferStrategy(2);
}
public Graphics2D getRenderGraphics() {
Window window = device.getFullScreenWindow();
if (window …Run Code Online (Sandbox Code Playgroud)