Adude11
Adude11

Reputation: 605

Java font much smaller than it should be

I'm having a problem with the font size, it is much smaller than it should be and even increasing the size parameter makes no difference.

The preferred size is to show that it's not the size constricting it, and the text is random and long to show how small the text is. It is all fonts as well not just sans-serif, but if I use a system default font it is normal. I also restarted my computer to make sure it hadn't loaded the font into cache wrong.

JLabel time = new JLabel("sdfghgfdcfghgvghbvhgvghhvghgvghhbhbhb");
time.setFont(new Font("sans-serif", 13, Font.ITALIC));
time.setPreferredSize(new Dimension(50, 50));
panel.add(time);

panel is just a JPanel with a normal flowlayout.

Here is an image of the text:

The text is approximately 5 pixels tall. Thanks

Upvotes: 2

Views: 778

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285415

time.setFont(new Font("sans-serif", 13, Font.ITALIC)); // not so good

Check the order of the constructor parameters.

time.setFont(new Font("sans-serif", Font.ITALIC, 13)); // better

Remember, the API is your friend. :)

Upvotes: 7

Related Questions