求助:IDEA Swing 中文 方块 乱码 字体

同样的代码,自己在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,黑体,
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值