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

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

问题描述

如果您的显示器的DPI超过150(例如Macbook Pro),您也可能会发现问题: Java Swing应用程序的字体对于高DPI显示器来说太小 ,我根本不能改变字体大小(它直接忽略Windows DPI,只显示 原始的DPI - > 96 )。我可以做任何事情,但改变屏幕分辨率,这可能绝对使液晶上的一切模糊。

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



问题没有解决方法吗?你有一个高DPI显示器?你如何做这样的应用程序? Swing是否会放弃高DPI用户?

解决方案

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

大多数Swing Look&感觉不支持高DPI,即使它应该是可扩展的,甚至不支持Nimbus。我发现一些旧的博客文章说Nimbus最终可能会提供较高的DPI缩放比例,但显然这是从来没有发生过的。

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



您也可以在Swing中设置一个比例因子。具体的LAF必须提供处理缩放的代码。所以最好的办法是选择System,希望它足够好。然而,JavaFX可以在我的系统上正确自动扩展到150%。如果可能,我建议你使用JavaFX来构建你的GUI。

编辑:我做了一些小测试程序,并为各种GUI框架,Swing主题和DPI设置。这可能是阅读这个问题的人们的信息: http://kynosarges.org/GuiDpiScaling.html


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.

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.

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?

解决方案

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

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.

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

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.

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.

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天全站免登陆