1

I have a swing application with this code, which attempts to resize the font of a component:

Font f = new Font(Font.SERIF,Font.PLAIN,16);
component.setFont(f);

The program loads with 14 point font, and I include a component which lets the user resize the component to 16 point font as above. When I run this on the computer I compiled it on (Debian), it works as intended, but I tested it on a Mac and a Windows computer and the font resizing feature doesn't work at all. However, on all platforms the font is serif. Any ideas why this is happening?

user156213
  • 736
  • 4
  • 12
  • 1
    The question is already asked: maybe [this](http://stackoverflow.com/a/11997304/1340559) could help you. – Tempia Andrea Mar 24 '15 at 14:34
  • Not really; the person there was asking for the exact same font across all platforms. Whatever serif font on a platform is fine to me, but I just want a way to resize the font (i.e. the application loads with 14 point font. when I set the font size to 16 on debian using a component which lets the user choose the font, the font resizes, but when I set it to 16 on windows, nothing happens) – user156213 Mar 24 '15 at 14:42

1 Answers1

1

The component's default UI delegate on your platform may be pre-empting your setting. In the alternative, consider one of the following:

  • Use deriveFont() on the existing font, illustrated here.

    component.getFont().deriveFont(16f)
    
  • Use an available sizeVariant, illustrated here.

size variant

  • Use a custom UI delegate, illustrated here and here.

custom UI delegate

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045