Java Swing中的HiDPI支持可实现多种外观 [英] HiDPI support in Java Swing for multiple look and feels

查看:144
本文介绍了Java Swing中的HiDPI支持可实现多种外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为某些Swing应用程序添加Hi-DPI支持,但是我找不到能满足我需求的解决方案.我需要支持多种外观感觉,所以情况似乎比我发现的其他帖子要复杂得多(这些帖子通常会建议调整您的UI大小以匹配您的字体大小").

一些实验发现,UIManager包含许多指标,可以对其进行调整,以使您在使应用程序对Hi-DPI友好的过程中获得一个良好的开端. ( UIManager-Defaults 实用程序对于探索这些功能非常有用!)但是我发现,L& F似乎在完全上彼此完全不同地工作:

  • Windows L& F为您提供了很好的(不是完美的)默认字体大小,并且内置图标(如复选框和窗口图标)的大小也适当调整-但许多其他指标仍然不可行. /p>

  • 在Metal中,您可以分别更新UIManager中的字体.通过一些工作,您可以缩放内置的IconUIResource使其匹配.

  • 在Nimbus中,您只可以更新一个默认字体,其他字体就位...但是如何缩放内置图标并具有组合框,单选按钮(等等),这超出了我的范围.渲染成功!

我从玩耍中得到的感觉是,应该有可能为每个L& F特定地创建一个特定的调整列表.这可能包括调整FontIconIntegerDimension的默认值.

有人对此提出好的解决方案吗?

任何人都可以共享需要针对标准L& F进行调整的UIDefaults的明确列表吗?

我对始终支持Metal和Windows的解决方案感到满意.

我想这样的解决方案应该是可重用的&;可以为一系列Swing应用程序解决相同的问题.我很惊讶似乎还没有这样的实用程序. (如果不能,请赐教!)这种方法当然不能解决所有问题(例如,您仍然需要手动缩放对setPreferredSize等的任何调用.然后,已经支持多种L& F的应用程序应该避免使用仍然可以调用它.)不过,我认为它可以使许多应用程序有个良好的开端.

我知道 JDK-9 承诺完整的解决方案

I'm looking to add Hi-DPI support to some Swing applications, but I have failed to find a solution sufficient to my needs. I need to support multiple look & feels, so the situation seems rather more complex than other posts I've found (which tend to suggest "adapt your UI sizes to match your font size").

Some experimentation has found the UIManager contains many metrics that can be tweaked to get you off to a good start in making an application Hi-DPI friendly. (The UIManager-Defaults utility has been invaluable for exploring these!) What I found though is that the L&Fs seem to work completely differently to each other:

  • Windows L&F gives you a good (not perfect) default font size, and built-in icons (like checkbox & window icons) are sized appropriately - but many other metrics are still out of whack.

  • In Metal you can update the fonts in the UIManager individually. With a bit of work you can scale the built-in IconUIResources to match.

  • In Nimbus you can just update a single default font, and the other fonts fall into place... but it's beyond me how to scale the built-in icons and have combo-boxes, radio buttons (etc) render successfully!

The feeling I get from playing around is that it should be possible to create a list of specific tweaks for each L&F-specific independently. This would comprise potentially tweaking the defaults for Font, Icon, Integer and Dimensions.

Has anyone come up with a good solution to this?

Can anyone share a definitive list of which UIDefaults need adjustment for the standard L&Fs?

I would be happy with a solution that just supports Metal and Windows consistently.

I imagine such a solution should be quite reusable & could solve the same problem for a range of Swing apps. I'm surprised no such utility yet seems to exist. (Please enlighten me if not!) This approach won't solve everything of course (for example you'd still need to manually scale any calls to setPreferredSize etc. Then again apps that already support mulitple L&Fs should tend to avoid calling that anyway.) Still, I imagine that it could get many apps off to a good start.

I'm aware that JDK-9 promises full Hi-DPI support, but I cannot wait that long - I may not be able to switch for some time even after it's 2017 release.

解决方案

  • not an answer, just my insights to this problematics issue, and please don't delete this answer, it can be very informative for the next one, two year,

  • my points, (I'm restrict to lazy Win user, could be interesting the experiences by real power users from LI/(U)NIX or OSX)

    1. tend to returns back use NullLayout, despite the fact that the UIManager (I think that this is still a true) is able handling with getPreferredSize 21k x 48k, but seems like as LayoutManager doesn't know to divide those value properly, you can see it, this issue you can see by using GridBagLayout, there is reall issue with scaling/zoom_in for 4k sceens, I think that AWT/Swing GUI is rendered correclty at 2k monitors,

    2. for 2k/4k screens you have to overide all Keys in UIManager (e.g. AFAIK for Nimbus L&F is possible to use structure stored in xml file directly)

      • have to create own paintIcon (in AWT/Swing are used simple shapes)
      • override Borders
      • override mouse events
      • override Focus events
    3. those steps are partially required for "smooth GUI" in todays aplications too, from old 4:3 screens -> thought laptops with small_screens with low resolutione (HD_screens) -> fullhd screen -> fullhs wide sceen, ends with 2k screen, note I'm never tried by using the sizing varians builts in Nimbus L&F, profesional application must contains test, checking for

      • Native OS (there is difference betweens font, border, sizing)
      • get a screen resolution in pixels from primary display with screen scalling, e.g., especially FullHd screen (16:9) and wide FullHd screen (21:9)
      • to cache all displays in the case that you have the multiple monitors and resolution in pixels is different (problem is in the case that there are two the same monitors, but there is discreasing setting - users settings to GPU, or monitor has active TV card - settings can be modified by TV chip)

      • then GUI can be created with hardcoded matrix for various sizing, to fits all screen standards, by default with success by override getPreferredSize for (parent) container(s), then LayoutManager will accept getPreferredSize form hardcoded matrix as prototype and do own job correctly,

    4. if I remember another interesting facts, bugs, and whatever, ... etc I'll edit this my longer comment, with my remarks

这篇关于Java Swing中的HiDPI支持可实现多种外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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