Java Graphics.drawString() font as JLabel

fonts, graphics, java, jlabel, swing

Solution

`UIManager.getFont("Label.font")` should work under most look & feels

Problem

How to make `Graphics.drawString()` get exactly the same font as that of `JLabel`? I've tried all the fonts I could find in `UIManager.getDefaults()` but even if I use the followings to make the String that drawString() not that thin as before. ``` ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); ``` It still looks a little bit different.

Original source