2

In java.awt package, we have the Font class. I want to see a list of all available fonts I have.

According to the documentation, this is possible through the GraphicsEnvironment#getAllFonts() method, but it is an abstract class. Why would I have to extend it, if it's supposed to tell me what fonts I have? The documentation for GraphicsEnvironment has no non-abstract subclasses, so I am confused on how I can view my options.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • If an abstract class has concrete `static` methods, nothing stops you from using them directly. – PM 77-1 Nov 15 '21 at 22:40
  • Correction: GraphicsEnvironment has no *public* non-abstract subclasses. AWT implementations are free to return a concrete implementation of GraphicsEnvironment whose class is not covered in the API documentation. – VGR Nov 16 '21 at 00:19

1 Answers1

3

To get a concrete instance of a GraphicsEnvironment, call the static method GraphicsEnvironment.getLocalGraphicsEnvironment()

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

Examples of use can be seen in answers to:

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433