如何在 Windows/Linux 上设置 Java Swing 应用程序的 DPI? [英] How to set the DPI of Java Swing apps on Windows/Linux?

查看:45
本文介绍了如何在 Windows/Linux 上设置 Java Swing 应用程序的 DPI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有一台 DPI 超过 150 的显示器(例如 Macbook Pro),您可能还会发现问题:Java Swing 应用程序上的字体太小,无法使用高 DPI 显示器,我根本无法更改字体大小(它直接忽略 Windows DPI,只显示 非常原始的 DPI-->96 ).我只能更改屏幕分辨率,这绝对会使 LCD 上的所有内容都变得模糊.

If you have an monitor with a DPI over 150 (such as Macbook Pro), you may also find the problem: the font on the Java Swing app is too small for high DPI monitor, and I cannot change the font size at all ( It ignores the Windows DPI directly, only displaying the very original DPI-->96 ). I can do nothing but changing the screen resolution, which could absolutely make everything blurry on LCD.

是的,我有一台配备高 DPI 显示器的笔记本电脑,15.6' 分辨率为 1920x1080,一些 Java 桌面应用程序在我的笔记本电脑上看起来很小,例如 Matlab、Burpsuite 等.我在互联网上搜索了很长时间时间,但仍然找不到解决问题的方法.我知道我可以通过 JRE_HOME/lib/font/fontconfig.properties.src 更改 JRE 字体,但是我找不到任何地方可以为 Java 桌面字体设置默认字体大小或 DPI.

Yes, I have a laptop with a high DPI monitor, 15.6' with 1920x1080 resolution, some Java desktop apps look very small on my laptop, such as Matlab, Burpsuite etc. I have been searching the Internet for a very very long time, but still cannot find a method for the problem. I know I can change the JRE fonts through JRE_HOME/lib/font/fontconfig.properties.src, but I cannot find any place to set the default font size or DPI for Java desktop fonts.

问题没有解决办法吗?你有高 DPI 显示器吗?你如何处理这些应用程序?Swing 会放弃高 DPI 用户吗?

Does the problem have no solution? Do you have a high DPI monitor? How do you do with such apps? Does Swing give up high DPI users?

推荐答案

我目前正在 Windows 上调查此问题.这是我发现的:

I'm currently investigating this issue on Windows. Here's what I found:

最摇摆的造型感觉根本不支持高 DPI,甚至不支持 Nimbus,即使它应该是可扩展的.我发现一些旧博客文章说 Nimbus 最终可能会提供高 DPI 缩放,但显然这从未发生过.

Most Swing Look & Feels don't support high DPI at all, not even Nimbus even though it's supposed to be scalable. I found some old blog posts saying that Nimbus might eventually offer high DPI scaling, but apparently that never happened.

一个例外是系统 LAF,但在所有 DPI 设置下,其默认字体比实际系统字体大小小约 10%.此外,必须按照此处所述明确选择系统:http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

The one exception is System LAF but its default font is ~10% smaller than the actual system font size, at all DPI settings. Moreover, System must be selected explicitly as described here: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

您也无法在 Swing 中设置单一的缩放因子.特定的 LAF 必须提供代码来处理缩放.所以你能做的最好的事情就是选择系统并希望它足够好.

There's no single scaling factor that you could set in Swing, either. The specific LAF has to provide code to handle scaling. So the best you can do is select System and hope it's good enough.

但是,JavaFX 在我的系统上可以正确并自动一直扩展到 150%.如果可能的话,我建议您使用 JavaFX 来构建您的 GUI.

However, JavaFX does correctly and automatically scale all the way up to 150% on my system. If at all possible, I suggest you use JavaFX to build your GUI.

我制作了几个小测试程序,并对各种 GUI 框架、Swing 主题和 DPI 设置进行了比较截图.这可能对阅读此问题的人有用:http://kynosarges.org/GuiDpiScaling.html

edit: I made a couple small test programs and took comparison screenshots for various GUI frameworks, Swing themes, and DPI settings. This might be informative for people reading this question: http://kynosarges.org/GuiDpiScaling.html

这篇关于如何在 Windows/Linux 上设置 Java Swing 应用程序的 DPI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆