The proper way for a `BasicLookAndFeel` subclass to activate anti-aliasing in Java 11 is:

huangapple go评论85阅读模式
英文:

What's the proper way for a `BasicLookAndFeel` subclass to activate anti-aliasing in Java 11?

问题

I have this in-house Swing Look & Feel, and as is usual for a migration to Java 11, usages of SwingUtilities2 members are to be replaced by official APIs.

Most are solved, but I haven't found any working advice on how to handle anti-aliasing.

The Look & Feel (L&F) is built as a subclass of BasicLookAndFeel, which has mechanisms for anti-aliasing. However, these mechanisms require activation through defaults.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, AATextInfo.getAATextInfo(SwingUtilities2.isLocalDisplay()));, which replicates what other Swing L&Fs do to enable AA. Unfortunately, with Java 11, this API isn't accessible anymore.

I have tried adjusting RenderingHints in various places, but the settings don't seem to take effect. While analyzing the situation using the debugger, I've discovered that BasicLookAndFeel seems to be hardcoded to use AATextInfo objects for passing hints, which I can't use if I maintain my own L&F.

So, what options do I have? Using a different base class might be possible, but it's a bit daunting.

(Note: @kleopatra has referred to anti-aliasing as a "story-without-happy-ending," but my concern is about utilizing the preconfigured hints and applying them correctly, rather than toggling AA on or off intentionally.)

英文:

I have this in-house Swing Look&Feel, and as is usual for a migration to Java 11, usages of SwingUtilities2 members are to be replaced by official APIs.

Most are solved, but I haven't found any working advice how to crack anti-aliasing.

The L&F is built as a subclass of BasicLookAndFeel, which has mechanisms for anti-aliasing; however, these seem to require activation through defaults.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, AATextInfo.getAATextInfo(SwingUtilities2.isLocalDisplay()));, which replicates what other Swing L&Fs are doing to enable AA, but with Java 11 this API isn't accessible anymore.
I have fiddled with setting RenderingHints in many likely and even some unlikely places, to no avail; for some reason, the settings never gain traction.

I am almost done analyzing the situation using the debugger (breakpoint on the L&F's LabelUI.paint() function and single-stepping through all the decisionmaking logic), but I found that BasicLookAndFeel seems to be hardcoded to use AATextInfo objects to pass hints, which I can't use if I maintain my own L&F.

So... what are my options?
I could probably use a different base class, but that's... scary.

(I know that @kleopatra has called anti-aliasing a "story-without-happy-ending", but this is about picking up the preconfigured hints and properly applying them, not about wilfully switching AA on or off.)

答案1

得分: 0

抗锯齿设置从外观中被JComponent.setUI()获取。
在Java 8中,它执行UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY)
在Java 9中,它执行UIManager.getDefaults().get(RenderingHints.KEY_TEXT_ANTIALIASING)

没有逐步过渡,因此您需要同时清理API并切换到较新的Java版本,而不是分开进行。

英文:

Anti-aliasing settings from the Look&Feel are picked up by JComponent.setUI().
In Java 8, it does UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY).
In Java 9, it does UIManager.getDefaults().get(RenderingHints.KEY_TEXT_ANTIALIASING).

There is no gradual transition so that you can clean up the API in one step and transition to a newer Java in a separate step, you have to do both at the same time.

huangapple
  • 本文由 发表于 2020年8月14日 19:45:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63412147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定