[英]Java/swing font resize not working across platforms
I have a swing application with this code, which attempts to resize the font of a component: 我有一个带有以下代码的swing应用程序,该应用程序试图调整组件字体的大小:
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. 该程序以14磅字体加载,并且我包含一个组件,该组件使用户可以如上所述将组件的大小调整为16磅字体。 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.
当我在(Debian)上的计算机上运行它时,它可以按预期工作,但是我在Mac和Windows计算机上对其进行了测试,并且字体大小调整功能根本不起作用。 However, on all platforms the font is serif.
但是,在所有平台上,字体均为衬线。 Any ideas why this is happening?
任何想法为什么会这样?
The component's default UI delegate on your platform may be pre-empting your setting. 您平台上组件的默认UI委托可能会抢占您的设置。 In the alternative, consider one of the following:
或者,请考虑以下之一:
Use deriveFont()
on the existing font, illustrated here . 使用
deriveFont()
对现有的字体,说明这里 。
component.getFont().deriveFont(16f)
Use an available sizeVariant
, illustrated here . 使用可用
sizeVariant
,说明这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.