当我尝试使用从Font.createFont返回的字体设置JLabel的字体时,JLabel不显示任何内容:
Font tempFont = Font.createFont(Font.TRUETYPE_FONT, new File("Path to a ttf font"));
Font font = tempFont.deriveFont(48);
JFrame frame = new JFrame();
JLabel text = new JLabel("Salam Jahan!");
text.setFont(font);
frame.getContentPane().add(text);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
有什么问题?
答案 0 :(得分:2)
deriveFont
指定字体样式而不是大小,以便加载的字体保留其默认大小0
Font font = tempFont.deriveFont(48);
您需要方法的重载版本
Font font = tempFont.deriveFont(48f);
^