2

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Adude11
  • 605
  • 5
  • 16

1 Answers1

7
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. :)

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Cos I just spent half an hour trying to find the problem and I had the parameters the wrong way round :( – Adude11 Jan 29 '13 at 21:43
  • 1
    Also consider `Font.SANS_SERIF`, rather than a string literal, or `deriveFont()`, illustrated [here](http://stackoverflow.com/a/14599176/230513). – trashgod Jan 30 '13 at 08:17