Xmagic
Xmagic

Reputation: 309

Java Graphics.drawString() font as JLabel

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.

Upvotes: 4

Views: 1141

Answers (2)

brimborium
brimborium

Reputation: 9512

How about new JLabel().getFont()?

Upvotes: 2

MadProgrammer
MadProgrammer

Reputation: 347204

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

Upvotes: 4

Related Questions