Java Swing 的文本框无法显示韩文,或者显示不方块,原因是字体原因,JDK默认字体在\jre\lib\fonts下:
下面代码是加载字体对象:
public class MStyle {
private static Font notoFont;
static {
File file = new File(MStyle.class.getResource("/resource/config").getPath() + "/NotoSansCJKtc-Black.ttf");
try {
notoFont = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, file);
notoFont = notoFont.deriveFont(java.awt.Font.PLAIN, 14);
} catch (Exception e) {
e.printStackTrace();
}
}
public static final Font simsun = new Font("宋体", Font.PLAIN, 13);
public static java.awt.Font getNotoSansCJKtc_Black() {
return notoFont;
}
}