In Java Swing, why is this font size incorrect?

Viewed 121

I've tried several versions of Java Swing, but this font size is always incorrect, when will it be fixed ?

JButton lButton=new JButton("\u24c1");
lButton.setFont(new Font("Monospaced",0,23));

JButton mButton=new JButton("\u24c2");               // (M) is always smaller, why ?!
mButton.setFont(new Font("Monospaced",0,23));

JButton nButton=new JButton("\u24c3");
nButton.setFont(new Font("Monospaced",0,23));

As you can see below, the (M) in the middle is always smaller, why ?!

enter image description here

1 Answers

The middle M most likely comes from a different font than the others. The circled M character is part of "emoji" (it can be used as a "metro" sign) so there are more fonts that include it than the circled L or N. Compare https://unicode-table.com/en/24C1/ and https://unicode-table.com/en/24C2/

To fix this, you may want to consider using a specific font instead of the "monospaced" logical font, as according to the java.awt.Font API specification:

Typically, each logical font name maps to several physical fonts in order to cover a large range of characters

Related