0

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.)

toolforger
  • 754
  • 7
  • 22
  • 2
    I always thought the usual way to enable anti aliasing is `-Dawt.useSystemAAFontSettings=on` and what about [this](https://stackoverflow.com/a/11990630)? –  Aug 14 '20 at 11:54
  • @a_horse_with_no_name the linked question is about switching anti-aliasing on and off for existing L&Fs. This question is about implementing a L&F in a way that settings like this actually work. – toolforger Aug 14 '20 at 15:36
  • Well, if your L&F does all the painting, then the [answer](https://stackoverflow.com/a/11990630) about the rendering hints should help. If your L&F does not painting itself, the global settings should help. –  Aug 14 '20 at 15:39
  • @a_horse_with_no_name Ah. I accidentally edited out that the L&F is a subclass of 'BasicLookAndFeel' and tries to reuse of that implementation as much as it can. – toolforger Aug 15 '20 at 07:55

1 Answers1

0

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.

toolforger
  • 754
  • 7
  • 22