如何更改 joptionpane 的大小和字体? [英] How do you change the size and font of a joptionpane?

查看:23
本文介绍了如何更改 joptionpane 的大小和字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能改变 JOptionPane 文本的字体和大小吗?我试过了,只有当我在那个特定的 java 类上运行文件"时它才有效.如果您启动整个项目,它不会更改字体.我只想更改特定的 JOptionPane 而不是全部.

Can you change the font and size of the text of a JOptionPane? I tried it and it works only if I "run file" on that specific java class. If you start the whole project it does not change the font. I only want to change only a specific JOptionPane not all of them.

代码如下:

 UIManager.put("OptionPane.messageFont", new FontUIResource(new Font(  
          "Arial", Font.BOLD, 18)));       
 JOptionPane.showMessageDialog(null,"MESSAGE","ERROR",JOptionPane.WARNING_MESSAGE);         

推荐答案

这真的很容易.JOption 窗格不仅接受字符串,还接受组件.因此,您可以创建一个标签,设置其字体并将其用作消息.

It's really easy. JOption pane accepts not only strings but also components. So you can create a label set its font and use it as message.

JLabel label = new JLabel("MESSAGE");
label.setFont(new Font("Arial", Font.BOLD, 18));
JOptionPane.showMessageDialog(null,label,"ERROR",JOptionPane.WARNING_MESSAGE);

我不明白为什么之前没有人回答这个问题

I don't understand why nobody answered this question before

这篇关于如何更改 joptionpane 的大小和字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆