我是否可以在不更改系统的DPI设置的情况下设置Java Swing应用程序的DPI分辨率? [英] Can I set the DPI resolution of my Java Swing application without changing the systems' DPI setting?
问题描述
我有一个使用Substance LookAndFeel和Windows作为目标平台的Java应用程序,我想增加我的应用程序的DPI设置,而不用更改系统设置。
I have a Java application using the Substance LookAndFeel with Windows as the the target platform and I want to increase the DPI setting of my application without changing the system setting.
我想这样做是因为我不想强迫用户重启Windows,因为许多Windows应用程序似乎都遇到了DPI设置非常高的问题(> 120)
I want to do this because I don't want to force the user to restart Windows and because many Windows applications seem to have problems with very high DPI settings (> 120)
PS:我知道Substance LaF允许在运行时缩放字体大小,但这样只调整控件的高度,而不是宽度。如果我设置系统的DPI设置,我希望我的GUI完全缩放。
PS: I'm aware that the Substance LaF allows to scale the font size at runtime, but that way only the height of my controls are scaled, not the width. I want my GUI fully scaled as it would happen if I set the system's DPI setting.
推荐答案
不知道是不是可能。外观和感觉必须支持它,据我所知,Windows外观和感觉不会。这是你可以考虑的一个黑客:迭代你的外观和感觉中定义的所有字体,并重新定义它们,使其变得更大。以下是执行此操作的代码段:
Don't know if that is possible. The look&feel would have to support it, and as far as I know, the Windows Look&Feel does not. Here's a hack which you may consider: Iterate through all the fonts defined in your look&feel and redefine them to be slighly bigger. Here is a code snippet that does this:
for (Iterator i = UIManager.getLookAndFeelDefaults().keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
if(key.endsWith(".font")) {
Font font = UIManager.getFont(key);
Font biggerFont = font.deriveFont(2.0f*font.getSize2D());
// change ui default to bigger font
UIManager.put(key,biggerFont);
}
}
我想你可以更进一步,重新定义按比例缩放边界,但这很快变得非常复杂
I suppose you could take this one step further and redefine scale borders proportionally as well, but that gets very complicated very quickly
这篇关于我是否可以在不更改系统的DPI设置的情况下设置Java Swing应用程序的DPI分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!