同样的代码,自己在cmd中编译运行就是正常界面。但是,
在IDEA中一键编译运行会发生:中文全部为方块。
通过查询,这不是编码问题(并不是乱码),而是没有中文字体。。。
另外,我的项目编码,文件编码等都设置的是UTF-8
。
求助:
public class Main {
public static void main(String[] args) {
// new MainFrame();
setUIFont();
showAllFont();
}
public static void showAllFont() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String script[] = ge.getAvailableFontFamilyNames();
for(String s:script){
System.out.print(s+",");
}
}
public static void setUIFont() {
Font f = new Font("宋体",Font.PLAIN,18);
String names[]={ "Label", "CheckBox", "PopupMenu","MenuItem", "CheckBoxMenuItem",
"JRadioButtonMenuItem","ComboBox", "Button", "Tree", "ScrollPane",
"TabbedPane", "EditorPane", "TitledBorder", "Menu", "TextArea",
"OptionPane", "MenuBar", "ToolBar", "ToggleButton", "ToolTip",
"ProgressBar", "TableHeader", "Panel", "List", "ColorChooser",
"PasswordField","TextField", "Table", "Label", "Viewport",
"RadioButtonMenuItem","RadioButton", "DesktopPane", "InternalFrame"
};
for (String item : names) {
UIManager.put(item+ ".font",f);
}
}
}
输出:
Arial,Arial Black,Arvo,Bahnschrift,Calibri,Calibri Light,Cambria,Cambria Math,Candara,Candara Light,Comic Sans MS,Consolas,Constantia,Corbel,Corbel Light,Courier New,Dialog,DialogInput,Droid Serif,Ebrima,Franklin Gothic Medium,Gabriola,Gadugi,Georgia,HoloLens MDL2 Assets,Impact,Indie Flower,Ink Free,Javanese Text,Leelawadee UI,Leelawadee UI Semilight,Lobster,Lucida Bright,Lucida Console,Lucida Sans,Lucida Sans Typewriter,Lucida Sans Unicode,Malgun Gothic,Malgun Gothic Semilight,Marlett,Microsoft Himalaya,Microsoft JhengHei,Microsoft JhengHei Light,Microsoft JhengHei UI,Microsoft JhengHei UI Light,Microsoft New Tai Lue,Microsoft PhagsPa,Microsoft Sans Serif,Microsoft Tai Le,Microsoft YaHei UI,Microsoft YaHei UI Light,Microsoft Yi Baiti,MingLiU-ExtB,MingLiU_HKSCS-ExtB,Mongolian Baiti,Monospaced,MS Gothic,MS PGothic,MS UI Gothic,MT Extra,MV Boli,Myanmar Text,Nirmala UI,Nirmala UI Semilight,Open Sans,Palatino Linotype,PMingLiU-ExtB,Poiret One,Raleway,Roboto,Roboto Condensed,Roboto Slab,SansSerif,Segoe MDL2 Assets,Segoe Print,Segoe Script,Segoe UI,Segoe UI Black,Segoe UI Emoji,Segoe UI Historic,Segoe UI Light,Segoe UI Semibold,Segoe UI Semilight,Segoe UI Symbol,Serif,SimSun-ExtB,Sitka Banner,Sitka Display,Sitka Heading,Sitka Small,Sitka Subheading,Sitka Text,Sylfaen,Symbol,Tahoma,TeamViewer14,Times New Roman,Trebuchet MS,Verdana,Webdings,Wingdings,Yu Gothic,Yu Gothic Light,Yu Gothic Medium,Yu Gothic UI,Yu Gothic UI Light,Yu Gothic UI Semibold,Yu Gothic UI Semilight,仿宋,宋体,微软雅黑,微软雅黑 Light,新宋体,楷体,等线,等线 Light,黑体,