Correctly getting the current font in Swing

Viewed 60

I'd like to get the current font used by my GUI to create a bold version of it. Which of the following solutions is to be preferred using pure Swing and why?

Font font = ...
  1. somethingExtendsAwtComponent.getFont();
  2. UIManager.getLookAndFeel().getDefaults().getFont("defaultFont");
  3. UIManager.getLookAndFeelDefaults().getFont("defaultFont");
  4. UIManager.getDefaults().getFont("defaultFont");

The Javadocs are not very helpful, only saying that 4. is to be used instead of 3. because alterations on the UIDefaults object returned can result in incorrect behavior, something that isn't the case here.

0 Answers
Related