import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionEvent; /** * Java中弹出对话框中的字体设置问题 * @author 五斗米 <如转载请保留作者和出处> * @blog http://blog.csdn.net/mq612 */ public class Test { JFrame frame; JButton button; Font font; public Test(){ font = new Font("宋体",0,12); UIManager.put("Button.font",font); UIManager.put("Label.font",font); frame = new JFrame("Test"); button = new JButton("弹出"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JLabel l = new JLabel("用户名或密码错误\\n请重新输入"); JOptionPane.showMessageDialog(frame,l,"错误",JOptionPane.ERROR_MESSAGE); } }); frame.getContentPane().add(button); frame.setSize(300, 200); frame.setVisible(true); } public static void main(String[] args) { new Test(); } } //源代码片段来自云代码http://yuncode.net